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

  • Home
  • SEARCH
  • 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 6220849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:01:51+00:00 2026-05-24T08:01:51+00:00

models: #StatusMessage model class StatusMessage < ActiveRecord::Base belongs_to :users default_scope :order => created_at DESC

  • 0

models:

#StatusMessage model
class StatusMessage < ActiveRecord::Base
  belongs_to :users
  default_scope :order => "created_at DESC"
end


#User Model
class User < ActiveRecord::Base
  has_many :status_messages 
end

In controller I want to join these two tables and get fields from both table. for example I want email field from User and status field from StatusMessage. When I use :

@status = User.joins(:status_messages)

Or

@status = User.includes(:status_messages)

It gives me only the user table data.

How can I implement this requirement?

  • 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-24T08:01:52+00:00Added an answer on May 24, 2026 at 8:01 am

    You need to use includes here. It preloads data so you won’t have another SQL query when you do @user.status_messages.

    And yes you can’t really see the effect: you need to check your logs.

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

Sidebar

Related Questions

Situation # Models class User < ActiveRecord::Base has_many :items end class Items < ActiveRecord::Base
Models: class User < ActiveRecord::Base has_many :attendances has_many :courses, :through => :attendances end class
my models class Auction belongs_to :item belongs_to :user, :foreign_key => :current_winner_id has_many :auction_bids end
models/user.rb class User < ActiveRecord::Base has_many :clubs, :dependent => :destroy has_many :announcements, :dependent =>
My models class Team < ActiveRecord::Base has_many :team_players has_many :players, :through => :team_players end
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
My models: class Order(models.Model): ordered_by = models.ForeignKey(User) reasons = models.ManyToManyField(Reason) class Reason(models.Model): description =
Models code: class Product < ActiveRecord::Base has_and_belongs_to_many :product_groups belongs_to :accessible_fields_group named_scope :sort_by_priority, :joins =>
My models: class Contact < ActiveRecord::Base has_many :addresses has_many :emails has_many :websites accepts_nested_attributes_for :addresses,
The models I'm working with look like this: class ComplexAssertion < ActiveRecord::Base has_many :expression_groups

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.