#14 ✓resolved
Sam Smoot

DataMapper::Base::embed should support options

Reported by Sam Smoot | November 13th, 2007 @ 12:03 AM


class Person < DataMapper::Base
  property :name, :string
  property :age, :integer
  property :occupation, :string
  property :type, :class
  property :notes, :text, :lazy => true
  embed :address, :prefix => 'address_', :lazy => true do
    property :street, :string
    property :city, :string
    property :state, :string, :size => 2
    property :zip_code, :string, :size => 10    

:lazy would lazy-load all the embedded values at the same time (the lazy_load! method already supports loading multiple attributes).

The :prefix option would define a column-prefix. So instead of mapping :street to a 'street' column, it would map to an 'address_street' column. ":prefix => true" might also be a short-cut to using "#{embedded_name}_" as the prefix (so in this case, it would be short for :prefix => "address_").

Also, embedded values should generate convenience methods that delegate to the EV's properties/accessors. So embed :address { property :street } would also create a Person.first.address_street so it can be easily used in #update_attributes= or for tag#name building. But Person#address_Street would delegate to Person#address#street in case you'd overridden it with a custom accessor.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket