On Feb 10, 7:26 pm, "Skye sh...@#$" <[email protected]> wrote:
> 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?

I'm not sure I understand what you want to do.  You want to select
from the current dataset, but return an instance of a different
model?  I can't understand why you'd want to do that, which is why I
find it unlikely I understand what you are attempting.

If the History model is just used for the Blog dataset, just do class
History < Sequel::Model(:blogs), and use the History dataset.  If the
History class is used to get the same behavior in multiple models,
then don't make it a class, make it a module and extend the necessary
instances with it.

Jeremy

-- 
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.

Reply via email to