Nadal
May 10, 2010, 10:36pm
#1
I am using rails3 edge.
class user < AR
has_many :books
end
Following statement is failing in console.
User.first.books.find(:conditions => {:title => ‘ror’})
ActiveRecord::RecordNotFound: Couldn’t find Book without an ID
It is such a basic thing that I am sure can’t fail.
Is it working fine for others?
Please test it with rails edge and not with beta3.
Thanks
Nadal
May 10, 2010, 10:43pm
#2
On 10 May 2010 21:34, Nadal [email protected] wrote:
I am using rails3 edge.
class user < AR
has_many :books
end
Following statement is failing in console.
User.first.books.find(:conditions => {:title => ‘ror’})
Don’t you need find(:all, :conditions…) or is that a rails 3 change?
Colin
Nadal
May 10, 2010, 10:50pm
#3
No. It is not a rails3 thing. It was just me being stupid.
Can’t believe I missed that. Spent so much time on this.
Thanks
Nadal
May 10, 2010, 11:13pm
#4
On Mon, May 10, 2010 at 1:34 PM, Nadal [email protected] wrote:
Nadal, the above syntax is marked for deprecation in Rails 3.1. Thus, I
would recommend using the newer
interfaces. Thus, you can write the above by doing the following:
User.first.books.where( :title => ‘ror’ )
I would recommend taking a look at the following screen cast:
http://media.railscasts.com/videos/202_active_record_queries_in_rails_3.mov
Also, Pratik has an excellent post on the subject that you can find
here:
http://m.onkey.org/2010/1/22/active-record-query-interface
Good luck,
-Conrad