Hello!

I'm not sure if I'm just not reading this correctly, but the results I'm 
getting when I use .direct_predecessors and .direct_successors are 
unexpected.

http://sequel.jeremyevans.net/rdoc/files/doc/association_basics_rdoc.html#label-Self-referential+Associations

So I have this schema in the example:
# Database schema:
#   nodes                edges
#   :id     <----------- :successor_id
#   :name         \----- :predecessor_id

And for demonstrative purposes I do a query like this:
SELECT predecessors.id, predecessors.name, successors.id, successors.name
FROM nodes AS predecessors, nodes AS successors, edges
WHERE predecessors.id = edges.predecessor_id
AND successors.id = edged.successor_id

This returns results like:
| Predecessor ID | Predecessor Name | Successor ID | Successor Name |
| 1              | Predecessor 1    | 2            | Successor 1    |
| 1              | Predecessor 1    | 3            | Successor 2    |
| 1              | Predecessor 1    | 4            | Successor 3    |

So if I have the node Predecessor 1, and I call .direct_successors on that 
node, I expect to get a dataset containing each of the nodes in the last 2 
columns.

I've set up my Node class like the example:
class Node
  many_to_many :direct_successors, :left_key=>:successor_id,
    :right_key=>:predecessor_id, :join_table=>:edges, :class=>self
  many_to_many :direct_predecessors, :right_key=>:successor_id,
    :left_key=>:predecessor_id, :join_table=>:edges, :class=>self
end

Calling .direct_successors on a node does not get me the dataset I'm 
expecting, but .direct_predecessors does. Is it possible that the :left_key 
and :right_key in the in the association definitions are swapped? Am I not 
understanding this correctly? 

Thank you for your help!

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to