On 4 September 2010 01:27, Pito Salas <[email protected]> wrote: > Here's an example: > > class LineItem < ActiveRecord::Base > belongs_to :order > end > > class Order < ActiveRecord::Base > has_many :line_items > end > > my_line_item = LineItem.find(:zipcode => "12345") > > Order.find_by_line_item(my_line_item) # doesn't work > > Order.find_by_line_item_id (my_line_item) # does work > > I was surprised by this, because it seems to force me to make reference > to the id field of the line item, rather than referring to the LineItem > as a class or type in the Order.findxxx statement. > > Am I misunderstanding something or missing a trick?
I think you are missing a trick. Once you have my_line_item, to get the item's order just do my_line_item.order There is no need to use find at all. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: 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/rubyonrails-talk?hl=en.

