On Sun, 2010-06-13 at 15:36 -0700, Jeremy Evans wrote:
> On Jun 13, 12:58 pm, John Anderson <[email protected]> wrote:
> > OK, so let's say I have
> >
> > class Passenger < Sequel::Model; end
> >
> > then obviously
> >
> > Passenger.dataset.model
> >
> > returns Passenger. I initially thought that
> >
> > Passenger.dataset.naked.model
> >
> > would return nil, but it returns Passenger.
> >
> > A dataset from, say, DB[:passengers] doesn't even have model defined as
> > a method.
> >
> > IMHO, Dataset#naked should then remove the model method. Or am I missing
> > something obvious?
>
> Well, removing the model method is very different from having it
> return nil.
My thoughts exactly. I'm not sure which approach would work better in
the big picture.
I'm writing some code that needs a dataset, for filtering, but it needs
to come from a model, for validation and nice access to relationships.
In trying to do some sanity checking on the dataset, I ran into this
issue (I won't call it a problem yet ;-)
I guess it's a matter of consistency - datasets that come from db[...]
have no model method. Datasets that come from a model have a model
method even though they don't always return model instances. So
dataset.respond_to?( :model ) == false will tell me what I need, but
dataset.model.nil? will not, because it returns the model class both for
datasets that give back models, and datasets that give back hashes.
> It's possible to override naked to set model to nil, but
> what about using row_proc= to remove it? Also, how about the dataset
> destroy method?
I can't find docs on destroy - I'll go look at the code. Ah, OK. So
*that's* where the model method is defined. I looked for it for quite a
while, and here it turns up when I'm looking for something else 8-)
Anyway. For a dataset from naked, destroy wouldn't work because the
values returned from all would be hashes.
Passenger.naked.destroy
results in
NoMethodError: undefined method `destroy' for #<Hash:0xb6e7c3d4>
Which is perhaps another indication that dataset.naked currently has
some unexpected side effects. I'm guessing that naked was originally
intended to remove the row proc, and what's in question is whether it
should also remove the rest of the relationship between a dataset and a
model.
> I don't think these changes are worth the effort, but
> I'll certainly consider them if people here think they are a good
> idea.
I'm happy to code the changes and send a patch, if there's agreement
that it would be useful. For the moment though, it seemed to me that
there were too many possible ways forward to start writing code, and I
wanted to see what other folks thought.
bye
John
--
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.