Groups
Groups
Sign in
Groups
Groups
Ruby on Rails: Talk
Conversations
About
Send feedback
Help
ActiveRecord scope with advanced condition
36 views
Skip to first unread message
Ivo Reis
unread,
Apr 9, 2012, 6:40:50 AM
4/9/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Hi there,
Anyone knows how to use a scope with a table alias condition like:
SELECT *
FROM table_name
AS alias_name, alias_name2
Where alias_name.field = alias_name2.field
Or if anyone has other suggestion..
Thank you
Chris Morris
unread,
Apr 9, 2012, 2:38:47 PM
4/9/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Maybe this is the sort of thing you're looking for?
http://guides.rubyonrails.org/association_basics.html#self-joins
--
Chris
http://livingsocial.com
|
http://clabs.org
Ivo Reis
unread,
Apr 10, 2012, 4:42:51 AM
4/10/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
Hi there Chris, i already found a solution, but thanks anyway. I need
to check from 2 table entries where they have a field in common.
Here's the snippet:
> User.from("Users as u1, Users as u2).where("u2.LastName=u1.LastName AND
u1.id
!=
u2.id
")
Reply all
Reply to author
Forward
0 new messages