On Aug 27, 3:25 am, Maz <[EMAIL PROTECTED]> wrote:
> Many thanks, I understand how it works now (I hope).
>
> Inhttp://sequel.rubyforge.org/rdoc/files/doc/advanced_associations_rdoc...
> you might want to correct the simple Node model with the ':class
> => :Node'.

This isn't technically required in the ways the association is used.
Since the eager loader is specified, it doesn't need a class.

> Also, after the eager loader ancestors and descendants, you might put
> a little explanation along the lines :
>
> ===
> Taking ':descendants', it will eager load the data when you call it
> through ':eager'. It still hands to you only the tuples that you would
> get wihtout ':eager'. However, it will preload all descendants before
> handing the results to you.
> Note also that it will only preload the ones you filtered through the
> 'Node.filter' in the eager loader.
> For example, if Node has a 'color' attribute, and you used :
>     Node.filter(:parent_id => id_map.keys).exclude(:color =>
> 'white').eager(:descendants).all do |node|
>
> When you steps through all children, see below, you will only get
> descendants that matched, and not all.
>
> Node.filter(:id => 1).eager(:descendants).all do |root|
>   # Anonymous function which recurses through all children of a given
> node
>   prok = proc do |x|
>     p [(x.parent.label if x.parent), x.label]
>     x.children.each(&prok)
>   end
>   # Call the anonymous function on the selected node
>   prok.call(root)
> end
> ===
>
> At least, that's how I undertand it after your example.

That's not a bad idea.  Please send in a documentation patch and I'll
be happy to apply it.

> I find that the associations with keys which have the same name as the
> previous 'one_to_many' and 'many_to_one' is confusing things at first.
> If we were to replace, only in the eager loader, 'parent' with
> 'father', and 'children' with 'sons', then the example would be :
>
> Node.filter(:id => 1).eager(:descendants).all do |root|
>   # Anonymous function which recurses through all children of a given
> node
>   prok = proc do |x|
>     p [(x.associations[:father].label if x.associations[:father]),
> x.label]
>     x.associations[:sons].each(&prok)
>   end
>   # Call the anonymous function on the selected node
>   prok.call(root)
> end

My issue with that is that it creates a false assumption that you
can't have different associations with same keys.

> That would also better reflect the use of xxx.associations which is
> used inside the eager loader.
>
> In fact, the close interaction between 'parent', 'children' and
> 'descendants' did confuse me. Mainly the 'magically' linked
> node.associations[:parent], with node.parent. Adding to that, if you
> filter out some of the results, they are also excluded from
> node.children 'magically'.
>
> I also 
> rereadhttp://sequel.rubyforge.org/rdoc/classes/Sequel/Model/Associations/Ea...
> but it didn't helped me more.

Model#associations is documented, see 
http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html,
it's in the attributes section.

> Overall, I think documentation on associations lacks somewhere between
> simple and advanced usage. Also, I hardly ever used ActiveRecord, and
> comparing the two is even more confusing.

Honestly, writing documentation isn't my strong suit, especially when
it comes to good examples.  I'm happy to remove documentation patches,
though.

> And last, can I use one_to_many :descendants, instead of many_to_one ?
> It seems a lot more like a one_to_many to me, and it doesn't change
> the results, in this contrived example.

one_to_many is more semantically correct.  As you can see, in this
case it doesn't matter.

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