示例#1
0
 public function formatRelationship(Relationship $relationshipObj, array $value)
 {
     $referencedResource = $relationshipObj->getReferencedResource();
     if ($relationshipObj->getType() === Relationship::TYPE_MANY_TO_ONE) {
         return $this->formatResourceRow($referencedResource, $value);
     }
     if ($relationshipObj->getType() === Relationship::TYPE_ONE_TO_MANY) {
         return $this->formatOneToManyRelationship($referencedResource, $value);
     }
 }
 public function buildToManyQueries(Relationship $relationship)
 {
     if ($relationship->getType() !== Relationship::TYPE_ONE_TO_MANY) {
         throw new \InvalidArgumentException('relationship must be of type one-to-many');
     }
     return $this->buildQuery($relationship->getReferencedResource()) . $this->buildToManyWhereClause($relationship);
 }
 public function test_relationship_construction()
 {
     $rootResource = new Resource('my__0', 'myCoolResource', 'my_cool_table', 'my_cool_id');
     $referencedResource = new Resource('my__1', 'myRelatedResource', 'my_related_table', 'my_related_id');
     $relationship = new Relationship($rootResource, $referencedResource, 'many-to-one', 'my_cool_id');
     $this->assertEquals($rootResource, $relationship->getMainResource());
     $this->assertEquals($referencedResource, $relationship->getReferencedResource());
     $this->assertEquals(Relationship::TYPE_MANY_TO_ONE, $relationship->getType());
     $this->assertEquals('my_cool_id', $relationship->getJoinColumn());
 }