I have a simple association of header and item (1 : 1). when I say
class Header
include DataMapper::Resource
property :id, Serial
property :somedata
has 1, :item
end
class Item
include DataMapper::Resource
property :id, Serial
property :name, String
attr_accessor: full_name, String
belongs_to :user
end
Header.get(1).item
I would like to have a hook for item for doing some translation(say some initialization for full_name~updating the attr_accessor fields). This has to be generalized as I don’t want do a before method item on the header ..but hook method the item model. so that however the item is called the translation/initialization happens.
How can this be done?
I figured it myself. wanted to update in case it might be useful other people. just need define a method for that attribute.