>From the docs:"Note that any fields in the join table will override matching field names in the two joined tables. As a consequence, having an "id" field in the join table usually has the undesirable result of clobbering the "id" fields in either of the other two tables." I do have an ID field in the join table, and as a result it''s clobbering the ID field of the associated table. It appears I can specify my own "finder_sql". Any other way? Perhaps a :select option would be nice? thanks csn __________________________________ Yahoo! for Good - Make a difference this year. http://brand.yahoo.com/cybergivingweek2005/
I take it there must be some other data in this join table that you''re trying to keep track of--otherwise there would be no need for an id field. In that case, maybe you should think about turning the habtm relation into an intermediate Model, which has a belongs_to relationship with each of the original models. Somebody talked about that just a week ago or so on this list. Something like this, I think: class Reader has_many :readings end class Article has_many :readings end class Reading belongs_to :reader belongs_to :article end hth Brian On 12/24/05, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > >From the docs: > > "Note that any fields in the join table will override > matching field names in the two joined tables. As a > consequence, having an "id" field in the join table > usually has the undesirable result of clobbering the > "id" fields in either of the other two tables." > > I do have an ID field in the join table, and as a > result it''s clobbering the ID field of the associated > table. It appears I can specify my own "finder_sql". > Any other way? Perhaps a :select option would be nice? > > thanks > csn > > > > > __________________________________ > Yahoo! for Good - Make a difference this year. > http://brand.yahoo.com/cybergivingweek2005/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
The disadvantage to this method being that you can''t do @article.readers or @reader.articles. Of course this will be changing with the introduction of polymorphic associations in the next version of Rails: class Reader has_many :readings has_many :articles, :through => :readings end class Article has_many :readings has_many :readers, :through => :readings end class Reading belongs_to :reader belongs_to :article end Brian Green wrote:> > class Reader > has_many :readings > end > > class Article > has_many :readings > end > > class Reading > belongs_to :reader > belongs_to :article > end-- Posted via http://www.ruby-forum.com/.
On 12/24/05, Marc Love <marc.love-w5+zYyZo3JRBDgjK7y7TUQ@public.gmane.org> wrote:> The disadvantage to this method being that you can''t do @article.readers > or @reader.articles. Of course this will be changing with the > introduction of polymorphic associations in the next version of Rails:You can do it, just manually. (i.e. create the Article#readers and Reader#articles methods by hand.) It''s what I''m doing now.