Hi,
i’m getting really frusterated after a good two days of racking my
brains on this subject; i went through josh susser’s hasmanythrough
blog, and digged up the four pages all over the net about
self_referencial associations (very bad documentation, on ror’s side)
and i can’t seem to figure this out.
i’ve got a Tag model, just like any other Tag models go, but aside from
that, i want to associate a tag to itself, (just like making a user some
other user’s friend) so that could to something like:
undertags = tag.undertags # which is an array of tags…
in the database i added:
:table => “undertagships”
:columns => tag_id # this is like a user
=> undertag_id # this is like a friend
class Tag
. has_many :undertagships,
:foreign_key => ‘tag_id’,
:class_name => ‘Undertagship’
has_many :undertags,
:through => :undertagships,
:source => :b
end
class Undertagship
belongs_to :b,
:foreign_key => "undertag_id",
:class_name => "Tag"
end
walla! i can actually access some other tags via a tag object:
undertags = tag.undertags # which is an array of tags…
which is simply wondersplendiddifully great.
thing is, i don’t have access to any of the other methods. i.e, i can’t
do
@tag.undertags << array_of_undertags # ERROR - NO METHOD undertags=()
@tag.destroy # DOESN’T DESTROY ASSOCIATED undertags
@tag.undertags # no validation on creating Undertag.create{:tag_id => 1,
…}
…
how can i access all of these write / destroy / change attributes? how
is it possible that i can access undertags via @tag.undertags, but can’t
asign a value to them? ( !undertags=() ) is this a known bug on
has_many through?
?
many many, many, thanks.
s