-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
2
I've got 3 Models:
.../models/book/work.rb
class Book::Work
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :category, class_name: '::Book::Work::Category', inverse_of: :book_works
embedded_in :package, class_name: '::Book::Package', inverse_of: :works
field :name_full, type: String
end
.../models/book/work/category.rb
class Book::Work::Category
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
embeds_many :book_works, class_name: '::Book::Work', inverse_of: :categories
end
____
..../models/book/package.rb
class Book::Package
include Mongoid::Document
include Mongoid::Timestamps
field :name_short, type: String
field :name_full, type: String
field :name_abbr, type: String
field :name_market, type: String
field :instruction, type: String
field :cost, type: Float
embeds_many :works, class_name: '::Book::Work', inverse_of: :package
end
What I do: rails console:
Book::Category.create(name:'Category')
Book::Category.last.works.create(name_full:'Work')
work = Book::Category.last.works.last
Book::Package.create(name_full:'Package')
package = Book::Package.last
package.works << work
=
package.save
Book::Package.last.works
= []
But if I do this twice:
" package.works << work "
it will add this work once to my Book::Package.last.works. Also when I do like this:
" package.works << Book::Work.new(name_full: 'Work') "
then it works.
I use Rails 4.1.8, 4.2.0; Mongoid 4.0.0, 4.0.2; Ruby 2.15, 2.2.0; Mongod 2.6.6, 2.6.7, 2.4.13, 3.0 - all the same..