Ruby on Rails Saturday, September 4, 2010

Ar Chron wrote:
> Pito Salas 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
>>
>
> Probably not explaining this clearly enough (I blame the distillery
> masters at Lagavulin), but:

Wish I was there! Which of their Beer is available in the US?

>
> find_by_line_item fails - my_line_item is an instance of the class (an
> object) that does not have a 'line_item' attribute you indicated, it
> *is* a LineItem

It kind of does, in that Order has_many :line_items, no? And so that's
an ActiveRecord method on Order called line_items?

By the way, my_order.find_by_line_item fails with "no such method", not
just by returning [].

I wonder if my_order.find_by_line_items would work?

--
Posted via http://www.ruby-forum.com/.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment