鉴于:
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