Module: DataMapper::Address::Preferred
- Defined in:
- lib/dm-address/preferred.rb
Overview
Helper for determining a Preferred (or default address) for something, for example a billing address, where multiple addresses belong to record.
Adds the following Class method when included:
preferred_address(+method_name+)
This will create an Integer property: {method_name}_id and add an instance method method_name
.
For example:
class Person
include DataMapper::Resource
include DataMapper::Address::Preferred
has n, :addresses
preferred_address :default_billing
end
p = Person.new
p.default_billing_id = Address.last.id
p.default_billing # => Address.last
If {method_name}_id is not set, the self.addresses.first is returned.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
29 30 31 |
# File 'lib/dm-address/preferred.rb', line 29 def included(klass) klass.extend(ClassMethods) end |