#234 ✓resolved
abombss

before :save not called on associations children

Reported by abombss | May 3rd, 2008 @ 03:05 PM

Adding an instance to a one_to_many collection forces a db save but is not calling the before :save method on the associated object. I am using dm edge updated 5/3.


class Account
  include DataMapper::Resource
  include DataMapper::Timestamp

    property :id, Fixnum, :serial => true
    property :user_name, String
    property :created_at, DateTime
    has n, :tweets

    before :save, :update_magic_properties

end


class Tweet
  include DataMapper::Resource
  include DataMapper::Timestamp

    property :id, Fixnum, :serial => true
    property :content, Text
    property :created_at, DateTime
    property :account_id, Fixnum, :nullable => false
    belongs_to  :account

    before :save, :update_magic_properties

end


acct = Account.create(:user_name => 'abombss')
acct.tweets << Tweet.new(:content => 'Hello World')

The output from merb isn't showing up in the ticket... after running this :created_at = nil when the call to persist the child is made.

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

Pages