小编mrj*_*ke2的帖子

:在Rails 2.3.4中打破了has_many关联的自动保存属性?

在我将这个错误发布给rails团队之前,我想知道我是否做错了可能导致此行为的错误.具体来说,has_many关联的:autosave属性似乎没有按照文档工作.

供参考,这是最新的API文档: http://api.rubyonrails.org/classes/Acti ... ation.html

看一下"一对多示例"部分.我在测试应用程序中完全复制了代码,但它对我不起作用.具体而言,更新父对象,但不更新子对象.

我的架构如下:

create_table :posts do |t|
  t.string :title

  t.timestamps
end

create_table :comments do |t|
  t.text :body
  t.integer :post_id

  t.timestamps
Run Code Online (Sandbox Code Playgroud)

我的模型如下:

  class Post < ActiveRecord::Base
    has_many :comments, :autosave => true
  end

  class Comment < ActiveRecord::Base
    belongs_to :post
  end
Run Code Online (Sandbox Code Playgroud)

在控制台中,我运行以下命令(此时post和comments对象已经在DB中):

  post = Post.find(1)
  post.title # => "The current global position of migrating ducks"
  post.comments.first.body # => "Wow, awesome info thanks!"
  post.comments.last.body # => "Actually, your article should be named differently."

  post.title = "On the migration of …
Run Code Online (Sandbox Code Playgroud)

ruby orm activerecord persistence ruby-on-rails

7
推荐指数
1
解决办法
1309
查看次数

标签 统计

activerecord ×1

orm ×1

persistence ×1

ruby ×1

ruby-on-rails ×1