On Apr 29, 2:48 am, jeremyz <[email protected]> wrote: > DB[:tjoins,:t1s].select(:tjoins.*).where > (:tjoins__t1_id=>:t1s__id).and(:t1s__a1=>'A').all > works fine, but using > T1.eager_graph(:tjoins).where(:t1s__a1=>'A').select(:tjoins.*).all > generates a : undefined method `pk' for nil:NilClass > > but the generated sql seems OK : > SELECT `tjoins`.* FROM `t1s` LEFT OUTER JOIN `tjoins` ON > (`tjoins`.`t1_id` = `t1s`.`id`) WHERE (`t1s`.`a1` = 'A')
If you could post the full backtrace, I might be able to see what is going on. One thing I should note is that the title of the post contains best practices. In general, I wouldn't consider it a best practice to do what you are doing in terms of adding rows to the join table. I would recommend using the join table as a real model table. So instead of t1.add_t2(t2, 'blah') do: Tjoin.create(:t1=>t1, :t2=>t2, :ajoin=>'blah') Yes, it is more verbose, but you could do something like: Tjoin.add(t1, t2, 'blah') with the appropriate definition of Tjoin.add. One reason I'm hesitant to have the default association methods like add_association take multiple arguments and pass them along is it would encourage people to do things like this, when I think it is better to use a real model table. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
