ruby - The difference in Class.where(id: '1234') and Class.find_by id: '1234' -
I just came across a subtle difference between .where and .find_by < apparently . returns only _id of an object, while .find_by gives a hash. I can explain the difference between the two methods in Railway 4 and Mongoad. ?
Thank you in advance
Please read.
Obtaining an object from a database
To retrieve the object from the database, the active record provides several finder methods
The methods are: < / P>
... cutting ...
Where All the above methods
ActiveRecord :: Relationreturn an example.
Therefore the result of calling
and:
1.15 find_by
According to the method find_by finds some conditions first record match example For:
client.fund_first_name: 'lipo' # = & gt; # & Lt; Client ID: 1, first_name: "lipo" & gt; Client.Fund_FirstName: 'John' # = & gt; Zero
(emphasis my)
then the result of calling class.find_by (...) is the first thing found .
Comments
Post a Comment