Question

Given:

message = Message.find(1)

When I do:

message.update_attributes(:created_at => ...)

I see in the log:

SELECT `users`.* FROM `users` WHERE (`users`.`id` = 5) LIMIT 1
UPDATE `messages` SET `created_at` = '2011-08-30 12:41:01', `updated_at` = '2011-08-30 12:41:03' WHERE (`messages`.`id` = 1)

Why does it queries for users with id=5 ?

Some relevant code:

class CreateMessages < ActiveRecord::Migration
  def self.up
    create_table :messages do |t|
      t.integer "publisher_id", :null => false
      ...
      t.timestamps
    end
    add_index("messages", "publisher_id")
    execute "ALTER TABLE messages ADD FOREIGN KEY (publisher_id) REFERENCES users(id)"
  end

  def self.down
    drop_table :messages
  end
end
Was it helpful?

Solution

It appears as though you may have some sort of before filter set up. These are often used to carry out actions / checks before a method is run - such as checking that a user is logged in.

http://guides.rubyonrails.org/action_controller_overview.html#filters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top