Added utility method to extract values from field

Pass it a field name, it'll return an array of all of the values form that field.
This commit is contained in:
Josh Sherman 2013-09-16 12:59:16 -04:00
parent 38e5173823
commit dd6ba92e28

View file

@ -1691,6 +1691,30 @@ class Model extends Object
return $value; return $value;
} }
/**
* Field Values
*
* Pulls the value from a single field and returns an array without any
* duplicates. Perfect for extracting foreign keys to use in later queries.
*
* @access protected
* @param string $field field we want the values for
* @return array values for the passed field
*/
protected function fieldValues($field)
{
$values = array();
foreach ($this->records as $record)
{
$values[] = $record[$field];
}
array_unique($values);
return $values;
}
// }}} // }}}
} }