Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:19:16+00:00 2026-06-15T06:19:16+00:00

I have two tables users ——- id name organization_id organizations ———- id org_name org_unique_num

  • 0

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 id in().. that would be ugly.

Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:19:18+00:00Added an answer on June 15, 2026 at 6:19 am

    DataMapper will do all join job for you.

    you do not need to extract organizations for each user, this is done automatically.

    So, you simply fetch your users with this: User.all(:age.gt => 25)

    And each user will have its organization attached to it:

    User.all(:age.gt => 25).each do |user|
      p user.name
      # organization not yet fetched, only referenced
      p user.organization
      # now organization are fetched
      p user.organization.id       # display org ID
      p user.organization.org_name # display org name
      # etc
    end
    

    Regard “i do not need abc and xyz“, if they are Text columns, DataMapper will load them lazily, meant the data will be fetched only when requested via user.abc and user.xyz

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables- users and language with a foreign key link of their
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I Have two tables: Users and News. Table News has columns id, name, createdby,
I have two tables: Table Users UserId Name 1 John 2 Alice 3 Tom
I have two tables Table1 with list of users comma separated Name UserID abc
I have two tables Users (name, email, password, instance_id, etc...) example: james bond, james@abc.com,
I have two tables users registered_members I want to confirm values from user table
I have two tables Users Users_Role I decided to try to add a foreign
I have two tables - users and stores . there is a third table
I have two tables users and providers that have has_and_belongs_to_many relationship. The join table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.