-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Associations, Callbacks
-
Minor Change
I have two models:
class Npdb include Mongoid::Document field :number, type: String field :number_type, type: String field :_id, type: String, default: ->{ number } embeds_many :npdb_moves, store_as: 'moves' accepts_nested_attributes_for :npdb_moves end
and
class NpdbMove include Mongoid::Document field :np_operator_code, type: String field :valid_from, type: Date field :net_prefix, type: String field :full, as: :country_meaning_code, type: String field :company, type: String field :_id, type: String, default: ->{ valid_from } embedded_in :npdb index({valid_from: -1}) validates_presence_of :valid_from validates_uniqueness_of :valid_from after_find :fix_empty_prefixes protected def fix_empty_prefixes return if net_prefix.present? p npdb #returns nil p npdb? #returns false end
For me it seems logical, if I will have an access to the parent model in the fix_empty_prefixes method. Or should I use something else to get to parent object?
P.S. The same problem with the callback after_initialize
- related to
-
MONGOID-3834 unable to access parent when setting child attribute
- Closed