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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:32:15+00:00 2026-06-17T17:32:15+00:00

i have Author entity which belongs_to User. User has_many posts. Please advice how can

  • 0

i have Author entity which belongs_to User. User has_many posts. Please advice how can i show recent_posts on Author entity from User.

class User < ActiveRecord::Base
  has_many :posts, :foreign_key => "author_id"
end

class Post < ActiveRecord::Base
  attr_accessible :title, :content
  belongs_to :author, :class_name => "User"
end

class Author < ActiveRecord::Base
  belongs_to :user
  has_many :recent_posts, :through => :user,
          :class_name => "Post",
          :limit => 3,
          :order => "updated_at desc"
end

How recent_post should be done? Raw sql?

  • 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-17T17:32:16+00:00Added an answer on June 17, 2026 at 5:32 pm

    You want the :source option to has_many, which you use to specify the association on the other model, like so:

    has_many :recent_posts, :through => :user, :source => :posts, :limit => 3, :order => 'updated_at desc'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an entity Author which has a name can write 0
I was reading an article in which the author had implemented an Entity class
I have two classes: User : /** @Entity @Table(name=users) */ class User { /**
I have these two entities: Message entity class Message { /** * @ManyToOne(targetEntity=User) *
I have a class: public class Author : Entity { public virtual string ForeName
I have a persistent class Author with two fields: int id , String name
I have a domain class: class Author { String name static hasMany = [superFantasticAndAwesomeBooks:
I have this setup in my models: class Author(models.Model): name = models.CharField(max_length=100) class Topic(models.Model):
I have a content type called Author which is referred in another two content
How can I use two different tables for one entity in Symfony? I have

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.