Пример #1
0
 private function filter($operator, Select $select, $conditionSetName, $value)
 {
     $quotedAlias = $select->quoteWithAlias($this->relationship->getSourceTable()->getTableName(), $this->relationship->getSourceColumnName());
     switch ($operator) {
         case self::OP_NOT_EMPTY:
         case self::OP_CONTAINS:
             $operator = 'IN';
             break;
         case self::OP_NOT_CONTAINS:
         case self::OP_EMPTY:
             $operator = 'NOT IN';
             break;
     }
     return $select->whereConditionSet($conditionSetName, "{$quotedAlias} {$operator} (?)", new Expr($this->relationship->getFilterSubquery($value)));
 }
Пример #2
0
 /**
  * Get the reference that can be used to retrieve option pairs.  How we retrieve
  * this will vary for one-to-many vs many-to-many contexts.  In the case of
  * many-to-many fields, we grab it from the relationship definition rather than
  * the table metadata.
  *
  * @return array
  */
 public function getOptionPairsReference()
 {
     return $this->manyToManyRelationship->getOptionPairsReference();
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * @expectedException \Dewdrop\Exception
  */
 public function testMissingXrefTableMetadataThrowsException()
 {
     $relationship = new Relationship($this->table, 'fafafafa');
     $relationship->getSourceColumnName();
 }