#594 ✓resolved
Jox

Custom getters get overwritten in inherited models

Reported by Jox | October 15th, 2008 @ 11:57 AM

The Problem:


class Foo
  property :settings, Yaml
  def settings
    @settings ||= {}
  end
end

class Bar < Foo
  ...
end

Bar.new.settings => nil
Foo.new.settings => {}

This had been fixed (#378) but somehow must have sneaked in again. Or has there been an API change I failed to notice?

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 8th, 2009 @ 02:20 PM

    • Tag set to bug, dm-core, inheritance
    • State changed from “new” to “unconfirmed”
    • Assigned user cleared.
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 21st, 2009 @ 02:00 AM

    • State changed from “unconfirmed” to “confirmed”

    I can confirm this is still a problem.

    It has to do with how the property and relationship accessor/mutators are created. They will create a method if it is not already explicitly created within the model itself. This means if you define your custom accessor/mutator prior to defining the property it will not overwrite it.

    However this is not the case with methods defined in parent classes. The logic for this should probably be wrapped up into DataMapper::Model, it should create a new method only if one has not been explicitly defined in the current or parent models.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 31st, 2009 @ 12:38 AM

    • State changed from “confirmed” to “accepted”
    • Assigned user set to “Dan Kubb (dkubb)”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 7th, 2009 @ 01:33 AM

    • State changed from “accepted” to “resolved”

    I have changed the logic in dm-core/next so that if the method has been defined in DM::Resource, or any parent class, it will not override the method in the child class.

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