zhangjingl02 / activejdbc

Automatically exported from code.google.com/p/activejdbc
0 stars 0 forks source link

.include() fails to include parents when trying to build a tree structure of nodes #163

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

With this:

@BelongsTo(parent = Node.class, foreignKeyName = "parent_id")
public class Node extends Model { }

then this code:

Node.findAll().include(Node.class)

will include the child nodes but not the parents. 
(using findAll is a silly example here, but it would reproduce the bug)

Original issue reported on code.google.com by evan.leo...@gmail.com on 3 Jun 2012 at 8:36

GoogleCodeExporter commented 9 years ago
this should be easy to fix, seems you are using a table for a tree structure. 

Original comment by ipolevoy@gmail.com on 4 Jun 2012 at 7:21

GoogleCodeExporter commented 9 years ago
Yup, you got it :)

Original comment by evan.leo...@gmail.com on 5 Jun 2012 at 1:34

GoogleCodeExporter commented 9 years ago

Original comment by ipolevoy@gmail.com on 5 Jun 2012 at 2:47

GoogleCodeExporter commented 9 years ago
Thank you Igor. 

I was looking over the change to learn more about AJ internals and noticed this 
in the test:

   Node parent1 = sedan1.parent(Node.class);
   Node parent2 = sedan1.parent(Node.class);

   //should return cached parent in both cases
   a(parent1).shouldBeTheSameAs(parent2);

Did you mean to select parent2 from a different location than parent1? Its 
running the same code path for both sides of the comparision. Maybe its what 
you intended, just wasn't quite clear to me from looking at it that it is.

Thanks again!
Evan

Original comment by evan.leo...@gmail.com on 5 Jun 2012 at 3:48