Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created April 12, 2011 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/915852 to your computer and use it in GitHub Desktop.
Save tenderlove/915852 to your computer and use it in GitHub Desktop.
# totally contrived example
User.select(Account[:name]).join(:accounts).where(User[:id].in(Group.where(:name => 'foo')))
@ernie
Copy link

ernie commented Apr 13, 2011

Your example (self-referencing associations) is precisely the reason I need to maintaining the context, and can't stomach the Person[:name] solution. :( We need to "mount" the constraints, for lack of a better term, on the proper table alias. Squeel does that right now via mapping the hash keys (or keypaths in the case of children.children.children) against the corresponding joins in the JoinDependency, then grabbing the JoinAssociation's table. Hope that makes sense.

See my post in the other thread for the pull request for sample queries and actual output.

@ernie
Copy link

ernie commented Apr 13, 2011

Also, I think I'm stealing your "putting lipstick on a pig" line for Squeel. It just fits.

@tenderlove
Copy link
Author

lol! Please take it! :-D

@ernie
Copy link

ernie commented Apr 13, 2011

@tenderlove: see activerecord-hackery/squeel@f33784217e3bbb030c21

FWIW: evaluate was a typical case of overthinking -- I didn't like stomping on Kernel#eval, even though there's no reason to care in this case. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment