I have two tables
users
-------
id
name
organization_id
organizations
----------
id
org_name
org_unique_num
abc
xyz
organization_id in users table is foreign key to organizations table's id
class Organization
include DataMapper::Resource
property :id, Serial
property :org_name, String
property :org_unique_num, Integer
property :abc String
property :xyz String
has n, :users
end
class User
include DataMapper::Resource
property :id, Serial
property :name, String
property :organization_id, Integer
property :age, Integer
belongs_to :organization
end
I want to grab the user's record with joining Organization table where
user's age > 25. So the result should look like
user_id name organization_id org_name org_unique_num age
12 John 356 ATT 76763
38
35 Lisa 981 IBM 2376
28
So how can I achieve this? Please note I dont want column abc and xyz in
the result.
User.all(:age.gt => 25)
This will just give me users with age >25, but I want to grab user's org
info as well. Is it possible to do it one statement? or will have to do it
in multiple steps. Like collecting all user_id then pass to Organization
model to with org_id in().. that would be ugly.
Any help will be appreciated.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/datamapper/-/R7fqPsHJDdAJ.
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/datamapper?hl=en.