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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:06:07+00:00 2026-05-28T15:06:07+00:00

I have the following relationships setup: class Article < ActiveRecord::Base has_and_belongs_to_many :authors end class

  • 0

I have the following relationships setup:

class Article < ActiveRecord::Base
  has_and_belongs_to_many :authors
end

class Author < ActiveRecord::Base
  has_and_belongs_to_many :articles
end

I noticed that, although the join table articles_authors has timestamps, they do not populate when creating a new relationship. For example:

Author.first.articles << Article.first

It’s important that I keep track of when an author is associated with an article.
Is there a way that I can do this?

  • 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-28T15:06:08+00:00Added an answer on May 28, 2026 at 3:06 pm

    From the rails guides.

    The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don’t need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you’ll need to remember to create the joining table in the database).

    You should use has_many :through if you need validations, callbacks, or extra attributes on the join model.

    class Article < ActiveRecord::Base
      has_many :article_authors
      has_many :authors, :through => :article_authors
    end
    
    class Author < ActiveRecord::Base
      has_many :article_authors
      has_many :articles, :through => :article_authors
    end
    
    class ArticleAuthor < ActiveRecord::Base
      belongs_to :article
      belongs_to :author
    end
    

    If it still doesn’t work with that structure, then instead of using an array push, use a create.

    Author.first.article_authors.create(:article => Article.first)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have entity framework setup and I have the following relationships setup: AdListing (AdListingID,
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I've got my models setup for a many-to-many relationship: class Workshop < ActiveRecord::Base has_many
I have the following relationships set up: A HABTM B B belongsTo C C
Currently I have a database with the following relationships: One Client has multiple Entities
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have a few tables with the following relationships: Company hasMany Jobs, Employees, and
I have the following objects and relationships, Lecture >- Tests Test >- Questions Business
I have the following setup of models: User - has_many File (for userpics) Gallery

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.