[Rails] HABTM and getting to arrays from either direction
DWFrank
dwfrank at gmail.com
Tue Aug 8 22:04:23 GMT 2006
I didn't find exactly an answer on this one, so I'd like to get a
clarification from folks who live & breathe HABTM.
class foo
has_and_belongs_to_many :bars
end
class bar
has_and_belongs_to_many :foos
end
(and yes, I have a bars_foos table in my db)
def test_habtm
bar = Bar.new
foo = Foo.new
foo.bars<<bar
assert !foo.bars.empty?
assert !bar.foos.empty?
end
My first assert passes just fine. But the 2nd fails. Am I wrong on the
concepts of HABTM? Shouldn't the << operator add to the join table and
therefore the next find from either object return a non-empty array?
thx,
--dwf
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list