Created
November 15, 2015 02:31
-
-
Save cat-in-136/b4494cce06a06f438559 to your computer and use it in GitHub Desktop.
#ActiveRecord, count may not equal to length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child < ActiveRecord::Base | |
belongs_to :parent | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent < ActiveRecord::Base | |
has_many :child, :dependent => :destroy | |
accepts_nested_attributes_for :child, :allow_destroy => true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parent = Parent.new | |
parent.child.build | |
parent.child | |
# => #<ActiveRecord::Associations::CollectionProxy [#<Child id: nil, parent_id: nil, created_at: nil, updated_at: nil>]> | |
parent.child.length | |
# => 1 | |
parent.child.count | |
# => 0 | |
parent.child.size | |
# => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment