Search in sources :

Example 1 with PicWithObjectId

use of dev.morphia.test.query.TestLegacyQuery.PicWithObjectId in project morphia by mongodb.

the class TestQueriesOnReferences method testQueryOverLazyReference.

@Test
public void testQueryOverLazyReference() {
    final ContainsPic cpk = new ContainsPic();
    final Pic p = new Pic();
    getDs().save(p);
    final PicWithObjectId withObjectId = new PicWithObjectId();
    getDs().save(withObjectId);
    cpk.setLazyPic(p);
    cpk.setLazyObjectIdPic(withObjectId);
    getDs().save(cpk);
    Query<ContainsPic> query = getDs().find(ContainsPic.class);
    assertNotNull(query.filter(eq("lazyPic", p)).iterator(new FindOptions().limit(1)).tryNext());
    query = getDs().find(ContainsPic.class);
    assertNotNull(query.filter(eq("lazyObjectIdPic", withObjectId)).iterator(new FindOptions().limit(1)).tryNext());
}
Also used : FindOptions(dev.morphia.query.FindOptions) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) ContainsPic(dev.morphia.test.query.TestLegacyQuery.ContainsPic) Pic(dev.morphia.test.query.TestLegacyQuery.Pic) PicWithObjectId(dev.morphia.test.query.TestLegacyQuery.PicWithObjectId) Test(org.testng.annotations.Test)

Aggregations

FindOptions (dev.morphia.query.FindOptions)1 ContainsPic (dev.morphia.test.query.TestLegacyQuery.ContainsPic)1 Pic (dev.morphia.test.query.TestLegacyQuery.Pic)1 PicWithObjectId (dev.morphia.test.query.TestLegacyQuery.PicWithObjectId)1 Test (org.testng.annotations.Test)1