On Mar 19, 9:30 am, David Lee <[email protected]> wrote:
> It depends on what the "rest of Sequel's behavior" is. Right now,
> datasets derived from a Model always yield a Model object, even a
> dataset eagerly loaded via #eager. The only place where this pattern
> breaks is with eager_graph.
You could make the same argument for Dataset#graph. Unless you
specify a row proc, Dataset#each always yields
a hash with column symbol keys and column values, the only place where
is pattern breaks is with graph,
which changes Dataset#each to return a hash with table symbol keys,
and hash values.
Eager graph builds on top of graph, so it operates just like graph.
The only thing eager_graph does differently is that inside all it'll
take all graphed rows and construct an associations graph from it.
> The problem is that there's a pattern in Sequel where datasets derived
> from Models always yield Model objects to blocks passed to #each. I
> just checked, and even eager yields Model objects, not Hash objects.
> This is even true of eager_graph, as long as no arguments are passed
> into eager_graph.
eager does yield Model objects, as does eager_graph if you use all.
Using eager.each won't do what you want though, as it won't eagerly
load the records (you should probably be arguing for eager.each to
behave like eager.all if you want to be consistent). eager_graph.each
operates like graph.each.
> Furthermore, I would even argue that eager_graph.each currently does
> not behave like a graph at all, passing every row instead of building
> up the cached associations graph.
eager_graph.each behaves exactly like graph.each. Both return data
structures that are really trees, but a tree is a type of graph, so
it's not really misleading.
> I want to suggest that you define a method named #each_row to do what
> currently is being done with eager_graph.each if you want to keep the
> current behavior. Model.tinker.tinker.each should always yield Model
> objects.
Try the following:
MyModel.graph(OtherModel, :id=>:other_model_id).each{|r| ...}
See if you get model objects from that. Compare to:
MyModel.eager_graph(:other_model).each{|r| ...}
See how much of a difference in consistency there is.
> > Not to mention that I'm wouldn't be surprised if some people are
> > relying on the fact that Dataset#each for an eager_graphed dataset
> > yields a hash with model object values (it always has), so even if I
> > thought this idea had merit, I'd have to consider the backwards
> > compatibility issues.
>
> Sequel 3.0 :)
Like I mentioned in the other thread, I'm not using 3.0 as an excuse
to change things willy-nilly. It's a moot point anyway, since I don't
think this is a good idea.
> If you're still not convinced, I would urge you to include something
> in the docs for #each, explaining that #each does not guarantee what
> type of arguments will be passed to the block. I guess a similar
> explaination in #all would be useful as well: "#all always yields
> Model objects to the block if the dataset is a Model dataset."
The documentation for graph explains that rows are yielded as hash of
with hash values (or model object values if you are using models).
The documentation for eager_graph tells you to use all, and that if
you use each, you get a normal graphed result back (a hash with model
object values). So the documentation already covers this
information. each can actually return anything you want it to return,
since it can call a user provided row_proc, so I think your point
about each not guaranteeing what types of objects are yielded doesn't
make much sense. Since all just collects what is yielded by each, the
same is true for all.
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
-~----------~----~----~----~------~----~------~--~---