Exemplo n.º 1
0
 /**
  * Relation field related to an object
  *
  * @param string $key     A relation field key
  * @param Object $obj Target object to relate
  * @return self
  */
 public function relatedTo($key, $obj)
 {
     $this->where['$relatedTo'] = array("key" => $key, "object" => $obj->getPointer());
     return $this;
 }
Exemplo n.º 2
0
 public function testMergeWithRelationOperation()
 {
     $child1 = new Object("TestObject", "abc101");
     $op = new RelationOperation("foo", array($child1), null);
     $child2 = new Object("TestObject", "abc102");
     $op2 = new RelationOperation("foo", null, array($child2));
     $op3 = $op->mergeWith($op2);
     $this->assertTrue($op3 instanceof RelationOperation);
     $out = $op3->encode();
     // it adds child1, removes child2
     $this->assertEquals("Batch", $out["__op"]);
     $this->assertEquals(array($child1->getPointer()), $out["ops"][0]["objects"]);
     $this->assertEquals(array($child2->getPointer()), $out["ops"][1]["objects"]);
 }
Exemplo n.º 3
0
 /**
  * Query on the parent class where child is in the relation
  *
  * @param Object $child  Child object
  * @return Query
  */
 public function getReverseQuery(Object $child)
 {
     $query = new Query($this->parent->getClassName());
     $query->equalTo($this->key, $child->getPointer());
     return $query;
 }