That does look cool. I'll email you off-list.
On Tue, Jul 15, 2008 at 11:28 PM, Michael Koziarski
<[EMAIL PROTECTED]> wrote:
>
>> I think it would be nice to be able to do:
>>
>> Comment.university(boston).creator(current_user).commentable(post).all
>
> Indeed, that does look pretty nice, and very useful in some
> circumstances. But it could be implemented without touching the query
> generation code at all. You could automatically add proc based named
> scopes to the class when you define the associations. and allow those
> procs to take either ids or instances.
>
> I'd definitely prefer that approach to supporting hash keys referring
> to associations inside the query generation code.
>
>> Comment.find_all_by_university_id_and_creator_id_and_commentable_type_and_commentable_id(boston,
>> current_user, post.class.base_class.name.to_s, post.id)
>
> I'd never advocate anything quite as ugly as that. but something like
>
> post.comments_by_user_about(current_user, boston)
>
> would work fine too.
>
>> It's main advantage would be that it allows easy formation of dynamic
>> queries based on input:
>>
>> scope = Comment.scoped({:include => [:creator, :commentable]})
>> scope = scope.commentable(post) if post
>> scope = scope.university(params[:uni]) if params[:uni]
>> scope = scope.creator(current_user) if params[:created_by_me] == "1"
>> scope = scope.country(params[:country]) if params[:country]
>> @comments = scope.all
>
> This is a nice use case, care to work with nik on implementing it?
>
> --
> Cheers
>
> Koz
>
> >
>
--
Nik Wakelin
+64 27 424 5433
* Blog: http://codetocustomer.com/blog
* WWR: http://workingwithrails.com/person/7401-nicholas-wakelin
* Company: http://codetocustomer.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---