0

鉴于:

message = Message.find(1)

当我做:

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

我在日志中看到:

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)

为什么它用 查询用户id=5

一些相关代码:

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
4

1 回答 1

2

似乎您可能已经设置了某种前置过滤器。这些通常用于在运行方法之前执行操作/检查 - 例如检查用户是否已登录。

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

于 2011-08-30T13:04:12.743 回答