Siena + Gae You suggest me a way to do this optimized

13 views
Skip to first unread message

Kenneth Burgos Nivar

unread,
Feb 17, 2013, 2:02:57 PM2/17/13
to siena-...@googlegroups.com
@Entity
public class Parent extends Model {

    @Id(Generator.AUTO_INCREMENT)
    public Long id;

    public String name;

    @Owned(mappedBy = "myParent")
    public Many<Child> children;

    public Parent(String name) {
        this.name = name;
    }

    public static Query<Parent> all() {
        return Model.all(Parent.class);
    }
}

@Entity
public class Child extends Model {

    @Id(Generator.AUTO_INCREMENT)
    public Long id;

    public String name;

    public Parent myParent;

    public Child(String name) {
        this.name = name;
    }

    public static Query<Child> all() {
        return Model.all(Child.class);
    }
}

------
public class BasicTest extends UnitTest {

    @Before
    public void setup() {
        Fixtures.deleteAllModels();
    }

    @Test
    public void parentChild() {
        Parent parentGod = new Parent("God");

        Child childA = new Child("Angel1");
        Child childB = new Child("Angel2");
        Child childC = new Child("Angel3");

        childA.myParent = parentGod;
        childB.myParent = parentGod;
        childC.myParent = parentGod;

        childA.save(); childB.save(); childC.save();

        parentGod.children.asList().addAll(childA, childB, childC);

        parentGod.save();

        Parent parentGodFromDb = Parent.all().filter("name","God").get();

        assertEquals("God",parentGodFromDb.name);
        assertEquals("God",parentGodFromDb.children.asList().get(0).name);  //here is my problem

    }

*The property myParent in Child class is always empty myparent
*The children I can not read
from Parent class

Thank you
Reply all
Reply to author
Forward
0 new messages