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 7630373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:05:09+00:00 2026-05-31T06:05:09+00:00

User has_one UserProfile which has_one Community. Given a community_id, I want a list of

  • 0

User has_one UserProfile which has_one Community.

Given a community_id, I want a list of emails from the Users table.

How do I get a list of all User.email where community_id = 5?

The best I can find (which does work) is:

User.select(:email).joins(:user_profile).merge(UserProfile.for_community(5))

But it seems brute-force… is there not a way to do something simpler along the lines of this below?

User.user_profile.community(5)
  • 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-05-31T06:05:11+00:00Added an answer on May 31, 2026 at 6:05 am

    I don’t think you know what your code does…

    If the UserProfile has_one community, then the communities table must have a column titled user_id. That means there is only one User associated with any given community id.

    To solve your question, as stated, you could delegate the user method to the user_profile.

    class Community < ActiveRecord::Base
      belongs_to :user_profile
      delegate :user, to: :user_profile
    end
    

    Then you could do Community.find(community_id).user.email

    Hope that helps.

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

Sidebar

Related Questions

I would like to access profiles table from my Profile model which belongs_to :user
class User has_one :user_profile end class UserProfile belongs_to :user end I am rendering a
I have a list of UserProfile which may (or may not) have one or
I'm having trouble sorting a list of user profiles which I am passing to
The UserProfile has a one-to-one to 'User' and a many-to-one to Place class UserProfile(
model: User has_one :beta_invite before_save :beta_code_must_exist def beta_code_must_exist if beta_invite_id == beta_invite.find_by_name(beta_invite.id) user else
Now i'm using this code: User has_one User_extra User => :username, :email, :crypted_password, :salt,
I have User and Teacher models. Teacher belongs_to User and User has_one Teacher. Also
I have a User.rb model and a Donation.rb model. User.rb has_one :donation , and
I am having a user object which has one-to-many relation with Address object. My

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.