-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
We use Mongoid v3.1.0
We have:
class Canvas
...
include Mongoid::Document
embeds_many :shapes, class_name: 'CanvasShapes::BaseShape'
accepts_nested_attributes_for :shapes, allow_destroy: true
...
end
module CanvasShapes
class BaseShape
include Mongoid::Document
...
embedded_in :canvas
...
end
end
module CanvasShapes
class Circle < BaseShape
...
end
end
module CanvasShapes
class Triangle < BaseShape
...
end
end
module CanvasShapes
class Rectangle < BaseShape
...
end
end
And when I passed next params:
canvas_attributes: {
"foo": {
shapes_attributes: {
"foo":
}
}
}
mongoid ignores the '_type' attribute and saves Triangle as a Shape.
I've found the temporary fix: if in any place (for example in controller) an instance of CanvasShapes::Triangle was created (CanvasShapes::Triangle.new), it set type correctly.
I have found https://github.com/mongoid/mongoid/pull/1030, and it seems to the problem had to be solved, but maybe something was missed.
- is related to
-
MONGOID-3523 Mongoid::Errors::UnknownAttribute on rails development mode
- Closed