Inheritance: extends lithium\core\Object
 public function testBelongsToForeignKey()
 {
     $config = array('from' => $this->_image, 'to' => $this->_gallery, 'type' => 'belongsTo', 'fieldName' => 'gallery');
     $relation = new Relationship($config + array('key' => 'gallery_id'));
     $expected = array('gallery_id' => 5);
     $this->assertEqual($expected, $relation->foreignKey(array('id' => 5)));
     $relation = new Relationship($config + array('key' => array('gallery_id' => 'id')));
     $this->assertEqual($expected, $relation->foreignKey(array('id' => 5)));
 }
Exemplo n.º 2
0
 /**
  * Tests that queries are correctly generated for each relationship/key type.
  */
 public function testQueryGeneration()
 {
     $relationship = new Relationship(array('name' => 'Users', 'type' => 'hasMany', 'link' => Relationship::LINK_KEY_LIST, 'from' => 'my\\models\\Groups', 'to' => 'my\\models\\Users', 'key' => array('users' => '_id'), 'fieldName' => 'users'));
     $this->assertNull($relationship->query((object) array()));
     $keys = array(1, 2, 3);
     $expected = array('conditions' => array('_id' => $keys), 'fields' => null);
     $this->assertEqual($expected, $relationship->query((object) array('users' => $keys)));
 }
 public function testRespondsTo()
 {
     $query = new Relationship();
     $this->assertTrue($query->respondsTo('foobarbaz'));
     $this->assertFalse($query->respondsTo(0));
 }