public function testCanSetMultipleValidOptionsAtOnce() { $relationship = new Relationship($this->table, 'dewdrop_test_fruits_eaten_by_animals'); $relationship->setOptions(array('sourceColumnName' => 'fafafafa', 'xrefAnchorColumnName' => 'fofofofo')); $this->assertEquals('fafafafa', $relationship->getSourceColumnName()); $this->assertEquals('fofofofo', $relationship->getXrefAnchorColumnName()); }
/** * Register a many-to-many relationship with this table. This will allow * you to retrieve and set the values for this relationship from row * objects and also generate field objects representing this relationship. * * Generally, supplying the relationship name and the cross-reference table * name are all you need to do to register the relationship. However, if * Dewdrop cannot determine the additional pieces of information needed to * support the relationship, you can specify those manually using the * additional options array. * * Once registered, you can use the relationship name you supplied as if it * was a normal field. So, you can do things like: * * <pre> * $row->field('my_relationship_name'); * </pre> * * Or: * * <pre> * $this->insert( * array( * 'name' => 'Concrete DB column value', * 'foo_id' => 2, * 'my_relationship_name' => array(1, 2, 3) * ) * ); * </pre> * * In the latter example, Dewdrop will automatically save the cross-reference * table values following the primary INSERT query. * * @param string $relationshipName * @param string $xrefTableName * @param array $additionalOptions */ public function hasMany($relationshipName, $xrefTableName, array $additionalOptions = array()) { $relationship = new ManyToManyRelationship($this, $xrefTableName); $relationship->setOptions($additionalOptions); if (array_key_exists($relationshipName, $this->manyToMany)) { throw new Exception("Db\\Table: A ManyToMany relationship named \"{$relationshipName}\" already" . 'exists on this table. Please supply an alternative relationship name ' . 'as the second parameter to the hasMany() method.'); } $this->manyToMany[$relationshipName] = $relationship; return $this; }