Skip to content
Permalink
Browse files

Add constants to check the type of association.

Knowing whether an association contains one or many rows is useful for
hydrating data into rows.
  • Loading branch information...
markstory committed Dec 13, 2013
1 parent 1cc4b06 commit f3b4fdef1a60cb471cebb15facc5835db942a400
Showing with 33 additions and 0 deletions.
  1. +15 −0 Cake/ORM/Association.php
  2. +9 −0 Cake/ORM/Association/BelongsToMany.php
  3. +9 −0 Cake/ORM/Association/HasMany.php
@@ -49,6 +49,12 @@ abstract class Association {
*/
const STRATEGY_SELECT = 'select';
const ONE_TO_ONE = 'oneToOne';
const ONE_TO_MANY = 'oneToMany';
const MANY_TO_MANY = 'manyToMany';
/**
* Name given to the association, it usually represents the alias
* assigned to the target associated table
@@ -415,6 +421,15 @@ public function transformRow($row) {
return $row;
}
/**
* Get the relationship type.
*
* @return string Constant of either ONE_TO_ONE, MANY_TO_ONE, or MANY_TO_MANY.
*/
public function type() {
return self::ONE_TO_ONE;
}
/**
* Returns a single or multiple conditions to be appended to the generated join
* clause for getting the results on the target table. If false is returned then
@@ -161,6 +161,15 @@ public function attachTo(Query $query, array $options = []) {
->attachTo($query, $options);
}
/**
* Get the relationship type.
*
* @return string MANY_TO_ONE
*/
public function type() {
return self::MANY_TO_MANY;
}
/**
* Return false as join conditions are defined in the junction table
*
@@ -160,4 +160,13 @@ public function save(Entity $entity, $options = []) {
return $entity;
}
/**
* Get the relationship type.
*
* @return string MANY_TO_ONE
*/
public function type() {
return self::ONE_TO_MANY;
}
}

0 comments on commit f3b4fde

Please sign in to comment.
You can’t perform that action at this time.