E
Eduardo Scoz
Hi guys!
I've been trying to understand how the find_by_*() method on
ActiveRecord works, but couldn't find anything that could help. I think
that you guys can probably help me on that.
On Active Record, you can make a call like
user.find_by_first_name_and_last_name("eduardo"...)
and this will generate the sql to send to the database.
But how does that method gets created? ActiveRecord doesn't know what I
want to find until I actually make the call, and the number of different
combinations of parameters would probably be infinite for it to be
created during the object initialization, so (I imagine) the method must
be created __AFTER__ it was called.
So my question is, is it possible for an object to receive a call to a
method that doesn't exist, not throw a NoMethodError, and respond to
that call?
I hope my question makes sense!
Thank you!!!
I've been trying to understand how the find_by_*() method on
ActiveRecord works, but couldn't find anything that could help. I think
that you guys can probably help me on that.
On Active Record, you can make a call like
user.find_by_first_name_and_last_name("eduardo"...)
and this will generate the sql to send to the database.
But how does that method gets created? ActiveRecord doesn't know what I
want to find until I actually make the call, and the number of different
combinations of parameters would probably be infinite for it to be
created during the object initialization, so (I imagine) the method must
be created __AFTER__ it was called.
So my question is, is it possible for an object to receive a call to a
method that doesn't exist, not throw a NoMethodError, and respond to
that call?
I hope my question makes sense!
Thank you!!!