Is there a Sequel way to create a component object for a model?
I had tried playing around with variations of the following idioms,
with obvious shortcomings:
one_to_many :histories, :one_to_one => true, :key =>
[ :Type, :Identifier ], :reciprocal => nil,
:dataset => proc { self.class.dataset.select(:dbCreateBy) }
and
:dataset => proc {
ds = self.class.dataset
ds.select(...)
ds.row_proc = proc { |a| History.new(a[:dbCreateBy]) } #Tried
Extending Sequel::Model and History.load(a) too
ds
}
I also looked at using a eager_loader. This was all for fun, but
really, I don't need to load the data since it's already loaded in the
containing object's dataset. So I settled for the unsettling:
class Blog < Sequel::Model
#...
def after_initialize
@history = History.new(dbCreateBy)
end
def before_save
if @history
self.dbCreateBy = @history.dbCreateBy
end
end
end
Is there a Sequel way?
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.