Module: DataMapper::NestedAttributes::InstanceMethods
- Defined in:
- lib/dm-accepts_nested_attributes/nested_attributes.rb
Instance Method Summary collapse
-
#associated_instance_get(association_name, repository = :default) ⇒ Object
returns nil if no resource has been associated yet.
-
#sanitize_nested_attributes(attrs) ⇒ Object
This method can be used to remove ambiguities from the passed attributes.
Instance Method Details
#associated_instance_get(association_name, repository = :default) ⇒ Object
returns nil if no resource has been associated yet
190 191 192 |
# File 'lib/dm-accepts_nested_attributes/nested_attributes.rb', line 190 def associated_instance_get(association_name, repository = :default) send(self.class.association_for_name(association_name, repository).name) end |
#sanitize_nested_attributes(attrs) ⇒ Object
This method can be used to remove ambiguities from the passed attributes. Consider a situation with a belongs_to association where both a valid value for the foreign_key attribute and nested_attributes for a new record are present (i.e. item_type_id and item_type_attributes are present). Also see is.gd/sz2d on the rails-core ml for a discussion on this. The basic idea is, that there should be a well defined behavior for what exactly happens when such a situation occurs. I’m currently in favor for using the foreign_key if it is present, but this probably needs more thinking. For now, this method basically is a no-op, but at least it provides a hook where everyone can perform it’s own sanitization (just overwrite this method)
185 186 187 |
# File 'lib/dm-accepts_nested_attributes/nested_attributes.rb', line 185 def sanitize_nested_attributes(attrs) attrs end |