Are find_by and find_or_create_by depreacated?

Hey all !

I tried using both this methods on rails edge and got method missing ,
looked for them in a model.methds in “script/console” but no luck …
Anyone can help !?

Regards

Hi,

I tried using both this methods on rails edge and got method missing ,
looked for them in a model.methds in “script/console” but no luck …

you will not see those methods by using .methods on a new object since
the methods are dynamically created. Notice you can have a huge number
of combinations if you have a table with some fields, and Active Record
is not going to create every single of the possible methods for you
unless you are going to use them.

Suppose you are trying to execute
Model.find_all_by_size_and_color_and_model_and_material. Since that
method is undefined, method_missing will be invoked for your class, and
ActiveRecord will make “the magic” at that moment. It will check if the
signature of the method makes sense with the attributes for that
particular model, and if it does, it will execute the find for you.
Moreover, since ruby is dynamic, AR will define a method with that
signature on the fly for this class, so next time you call it you will
save all the process of hitting method_missing and so on.

This means you will not be able to see the method by invoking .methods
until you execute a find and it gets dynamically defined.

regards,

javier ramirez

Uh got it … more method_missisng Ruby Magic ! :slight_smile: Silly stupid
me ! :slight_smile:

Thanks !