This project is archived and is in readonly mode.

#3699 ✓wontfix
Lyle

Timestamps with has_and_belongs_to_many

Reported by Lyle | January 15th, 2010 @ 06:47 PM

I'm using Rails 2.3.5.

All of my tables include the default timestamps (created_at and updated_at) including my join tables for has_and_belongs_to_many (habtm) associations. When I retrieve the habtm objects using the convention task.colors, Rails returns the timestamps from the join table instead of the color table. Since it returns Color objects, the timestamps should be from the colors table since that reflects when the Color object was last updated.

Both tables have timestamps, is Rails confusing the two? Or is this by design?

class Task < ActiveRecord::Base
  has_and_belongs_to_many :colors
end
class CreateColorsTasks < ActiveRecord::Migration
  def self.up
    create_table :colors_tasks, :id => false do |t|
      t.integer 'color_id', :null => false
      t.integer 'task_id', :null => false
      t.timestamps
class CreateTasks < ActiveRecord::Migration
  def self.up
    create_table :tasks do |t|
      t.string 'name'
      t.timestamps
class CreateColors < ActiveRecord::Migration
  def self.up
    create_table :colors do |t|
      t.string 'name'
      t.timestamps

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages