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

Ah hah, your explanation about eager_graph being implemented on top of
graph helped me understand the problem at hand. I want eager_graph to
behave like eager, whereas you want eager_graph to behave like graph.
This was the first time I realized there was a graph method, and now I
understand why you want the current behavior.

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

I think that's where I feel the inconsistency. #all, #map, and #each
should always yield the same object. Right now, eager_graph acts like
eager sometimes and graph like sometimes.

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

The awkwardness is here:

  # Both yield Hash
  MyModel.graph(OtherModel, :id=>:other_model_id).all{|r| ...}
  MyModel.graph(OtherModel, :id=>:other_model_id).each{|r| ...}

  # Both yield MyModel
  MyModel.eager(:other_model).all{|r| ...}
  MyModel.eager(:other_model).each{|r| ...}

  # One yields MyModel, the other yields Hash
  MyModel.eager_graph(:other_model).all{|r| ...}
  MyModel.eager_graph(:other_model).each{|r| ...}

> 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

I was asking you to put documentation into #all and #each as well, not
only under eager_graph and graph. If you take a look at the docs for
#each and #all right now, you have no idea what kind of arguments will
be passed into the block.

> 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

This behavior should be documented under #all and #each.

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

Is this really the case? Isn't the whole problem that eager_graph.all
is not "just collecting what is yielded by each."

Now that I understand your reservations for changing the behavior of
eager_graph.each because it departs from the behavior of graph.each, I
suggest that eager_graph.all return the same thing as eager_graph.map.
Perhaps all could just be an alias to map.

There should also be an eager_* method that does not behave like
graph, but behaves like eager, while using join instead of a multi-
query process to build the associations. Maybe eager_join? Or just
eager(:other_model, :use_joins => true)?
--~--~---------~--~----~------------~-------~--~----~
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