I've been fiddling around a bit with the concept of adding "inferred
join" capabilities to a gem I've been working on.

The general idea, to me, is one that feels so "Rails-like" (as in,
principle of least surprise) that I was kind of surprised it wasn't
already in.

The goal: If you're selecting Articles, but the selection criteria are
based on stuff associated to articles, I shouldn't need to think about
what needs to be joined in advance if I don't want to. I should be
able to do...

Article.where(
  :title => 'Hello world',
  :comments => {
    :body => 'First post!',
    :moderations => [
      :value < 0
    ]
  }
)

...and end up with something like this:

SELECT "articles".*
FROM "articles"
  INNER JOIN "comments" "mw_infer_comments"
    ON "mw_infer_comments"."article_id" = "articles"."id"
  INNER JOIN "moderations" "mw_infer_moderations"
    ON "mw_infer_moderations"."comment_id" = "mw_infer_comments"."id"
WHERE ("articles"."title" = 'Hello world')
  AND ("mw_infer_comments"."body" = 'First post!')
  AND ("mw_infer_moderations"."value" < 0)"

I have this working, in rough form, at 
http://github.com/ernie/meta_where/tree/inferred_joins
(the relevant code is in meta_where/lib/inferred_join_dependency.rb
and query_methods.rb). It's a bit kludgy at the moment, but this is
only my first stab at it.

I'm just curious if:

a. Anyone on core would be interested in something like this. If not,
I'm happy to maintain it in MetaWhere, as well, provided....
b. Anyone has suggestions for an improved implementation.
JoinDependency, and the association code in general, is kind of a pain
to work around right now. I suspect that bypassing JoinDependency
altogether for an alternative implementation would yield performance
and readability improvements.

Thanks!

-- 
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 rubyonrails-c...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to