>
> (off topic: this discussion is good to see, as I will be taking it into 
> account on the metawhere rewrite)
>
So, since this thread and another are currently ongoing relating to complex 
queries and the handling of ARel predicates, I thought I'd make a quick 
announcement that the MetaWhere rewrite-in-progress for Rails 3.1 is up on 
GitHub and actively being worked on: 
https://github.com/ernie/meta_where/tree/rewrite

Specifically as a result of this thread, I've made core extensions opt-in, 
and am adding block syntax for those Relation methods where it makes sense. 
Hopefully this will alleviate some of the Symbol extension gripes that came 
up here. For example:

SQL Functions:
Person.select{max(id).as(max_id)}
=> SELECT max("people"."id") AS 'max_id' FROM "people"

ANDs and association mapping:
Person.joins(:comments).
       where{name >> 'bob' & {comments => body >> 'First post!'}}
=> SELECT "people".* FROM "people" 
   INNER JOIN "comments" ON "comments"."person_id" = "people"."id" 
   WHERE (("people"."name" = 'bob' AND "comments"."body" = 'First post!'))

The same query with an OR:
Person.joins(:comments).
       where{name >> 'bob' | {comments => body >> 'First post!'}}
=> SELECT "people".* FROM "people" 
   INNER JOIN "comments" ON "comments"."person_id" = "people"."id" 
   WHERE (("people"."name" = 'bob' OR "comments"."body" = 'First post!'))

Could also be written as:
Person.joins(:comments).
       where{name.eq('bob') | {comments => body.eq('First post!')}}

You get the idea. I'm still tweaking the operators, not so sure about >> for 
eq.

Anyway, this is the last MetaWhere-related post I'll make -- I just thought 
it might give a plugin option to those people who are looking for a way to 
get at the ARel goodness in AR and don't want to wait on something in core.

-Ernie

-- 
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.

Reply via email to