Just curious... Why isn''t there a ''before_find'' callback for ActiveRecord? _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
uh. because the objects are not instanciated/exist before they are actually found. Or is this a philosophical question? On 22 Apr 2006 20:35:53 -0000, Kevin Olbrich <devlists-rails-core@devlists.com> wrote:> Just curious... > > Why isn''t there a ''before_find'' callback for ActiveRecord? > > _Kevin > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >-- Tobi http://shopify.com - modern e-commerce software http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog
On 4/22/06, Tobias Lütke <tobias.luetke@gmail.com> wrote:> uh. because the objects are not instanciated/exist before they are > actually found. Or is this a philosophical question?Existential Rails Plugin :) Kevin: do you have a use case in mind? Surely anything you want done before_find can be done before the find call? -- Rick Olson http://techno-weenie.net
Well, what I''m thinking of would be more like a class-level before_find. I''d like to intercept the options going into ''find'', and pre-process them on a model-per-model basis, and then pass that along to ''find''. The general idea is to give models an ability to restrict which users can access individual records. To make it clean, I''d like to build it into the normal find process. So, yeah, a object level before_find doesn''t make sense, but a class level one does. Sure, I could write a plugin to do this, but it would essentially be adding a before_find call manually. On Saturday, April 22, 2006, at 4:49 PM, Rick Olson wrote:>On 4/22/06, Tobias L�tke <tobias.luetke@gmail.com> wrote: >> uh. because the objects are not instanciated/exist before they are >> actually found. Or is this a philosophical question? > >Existential Rails Plugin :) > >Kevin: do you have a use case in mind? Surely anything you want done >before_find can be done before the find call? > >-- >Rick Olson >http://techno-weenie.net >_______________________________________________ >Rails-core mailing list >Rails-core@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-core_Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
Implement your own find, do whatever you like to the parameters and then call the main ActiveRecord find. Look into the alias method. On 22 Apr 2006 23:09:07 -0000, Kevin Olbrich <devlists-rails-core@devlists.com> wrote:> Well, what I'm thinking of would be more like a class-level before_find. > I'd like to intercept the options going into 'find', and pre-process > them on a model-per-model basis, and then pass that along to 'find'. > The general idea is to give models an ability to restrict which users > can access individual records. To make it clean, I'd like to build it > into the normal find process. > > So, yeah, a object level before_find doesn't make sense, but a class > level one does. Sure, I could write a plugin to do this, but it would > essentially be adding a before_find call manually. > > On Saturday, April 22, 2006, at 4:49 PM, Rick Olson wrote: > >On 4/22/06, Tobias L�tke <tobias.luetke@gmail.com> wrote: > >> uh. because the objects are not instanciated/exist before they are > >> actually found. Or is this a philosophical question? > > > >Existential Rails Plugin :) > > > >Kevin: do you have a use case in mind? Surely anything you want done > >before_find can be done before the find call? > > > >-- > >Rick Olson > >http://techno-weenie.net > >_______________________________________________ > >Rails-core mailing list > >Rails-core@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails-core > > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >_______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
def find(*params) [..] before find code super end On 22 Apr 2006 23:09:07 -0000, Kevin Olbrich <devlists-rails-core@devlists.com> wrote:> Well, what I'm thinking of would be more like a class-level before_find. > I'd like to intercept the options going into 'find', and pre-process > them on a model-per-model basis, and then pass that along to 'find'. > The general idea is to give models an ability to restrict which users > can access individual records. To make it clean, I'd like to build it > into the normal find process. > > So, yeah, a object level before_find doesn't make sense, but a class > level one does. Sure, I could write a plugin to do this, but it would > essentially be adding a before_find call manually. > > On Saturday, April 22, 2006, at 4:49 PM, Rick Olson wrote: > >On 4/22/06, Tobias L�tke <tobias.luetke@gmail.com> wrote: > >> uh. because the objects are not instanciated/exist before they are > >> actually found. Or is this a philosophical question? > > > >Existential Rails Plugin :) > > > >Kevin: do you have a use case in mind? Surely anything you want done > >before_find can be done before the find call? > > > >-- > >Rick Olson > >http://techno-weenie.net > >_______________________________________________ > >Rails-core mailing list > >Rails-core@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails-core > > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >-- Tobi http://shopify.com - modern e-commerce software http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Yeah, I know how to do it that way. I''m just exploring other options. On Saturday, April 22, 2006, at 7:40 PM, Tobias Lütke wrote:>def find(*params) > [..] before find code > super >end > >On 22 Apr 2006 23:09:07 -0000, Kevin Olbrich ><devlists-rails-core@devlists.com> wrote: >> Well, what I''m thinking of would be more like a class-level before_find. >> I''d like to intercept the options going into ''find'', and pre-process >> them on a model-per-model basis, and then pass that along to ''find''. >> The general idea is to give models an ability to restrict which users >> can access individual records. To make it clean, I''d like to build it >> into the normal find process. >> >> So, yeah, a object level before_find doesn''t make sense, but a class >> level one does. Sure, I could write a plugin to do this, but it would >> essentially be adding a before_find call manually. >> >> On Saturday, April 22, 2006, at 4:49 PM, Rick Olson wrote: >> >On 4/22/06, Tobias L�tke <tobias.luetke@gmail.com> wrote: >> >> uh. because the objects are not instanciated/exist before they are >> >> actually found. Or is this a philosophical question? >> > >> >Existential Rails Plugin :) >> > >> >Kevin: do you have a use case in mind? Surely anything you want done >> >before_find can be done before the find call? >> > >> >-- >> >Rick Olson >> >http://techno-weenie.net >> >_______________________________________________ >> >Rails-core mailing list >> >Rails-core@lists.rubyonrails.org >> >http://lists.rubyonrails.org/mailman/listinfo/rails-core >> >> >> _Kevin >> >> -- >> Posted with http://DevLists.com. Sign up and save your mailbox. >> _______________________________________________ >> Rails-core mailing list >> Rails-core@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-core >> > > >-- >Tobi >http://shopify.com - modern e-commerce software >http://typo.leetsoft.com - Open source weblog engine >http://blog.leetsoft.com - Technical weblog > >_______________________________________________ >Rails-core mailing list >Rails-core@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-core >_Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
On 23/04/2006, at 3:09 AM, Kevin Olbrich wrote:> Yeah, I know how to do it that way. > I''m just exploring other options.The other way to accomplish what you want is to use finder scopes: http://habtm.com/articles/2006/02/22/nested-with_scope -- tim
Nice, that looks very handy for this purpose. On Monday, April 24, 2006, at 11:33 AM, Tim Lucas wrote:>On 23/04/2006, at 3:09 AM, Kevin Olbrich wrote: > >> Yeah, I know how to do it that way. >> I''m just exploring other options. > >The other way to accomplish what you want is to use finder scopes: >http://habtm.com/articles/2006/02/22/nested-with_scope > >-- tim >_______________________________________________ >Rails-core mailing list >Rails-core@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-core_Kevin , -- Posted with http://DevLists.com. Sign up and save your mailbox.