92,42 → 92,6 |
} |
|
/** |
* Returns an array containing the property-column mapping. |
* |
* @param array $propertyNames = null |
* Names of the properties that should be included. |
* The default is to include all persistent properties. |
* @return array |
*/ |
public static function getPersistentMapping (array $propertyNames = null) |
{ |
$a = array(); |
|
$persistent_properties = static::$_persistentProperties; |
|
if ($propertyNames === null) |
{ |
$propertyNames = $persistent_properties; |
} |
|
foreach ($propertyNames as $property_name) |
{ |
if (!array_key_exists($property_name, $persistent_properties)) |
{ |
$column_name = $property_name; |
} |
else |
{ |
$column_name = $persistent_properties[$property_name]; |
} |
|
$a[$property_name] = $column_name; |
} |
|
return $a; |
} |
|
/** |
* Returns an array for database queries containing the |
* property values of this object, using the specified |
* property-to-column mapping. |
166,11 → 130,12 |
* |
* @param mixed $id = null |
* The ID of the object to find. If <code>null</code> (default), |
* the object is searched for by its current ID. |
* the object is search for by its current ID. |
* @see Table::find(Model) |
* @return Model|null |
* This object filled with missing data, or <code>null</code> |
* if there is no data for this object |
* @see Table::find(int) |
* @see Table::find(Model) |
*/ |
public function find ($id = null) |
{ |
196,44 → 161,6 |
} |
|
/** |
* Finds the records for model objects in the table by value, |
* and returns the result. |
* |
* @param string $name |
* Name of the property to search for. |
* @param mixed $value = null |
* The property value to find. If <code>null</code>, |
* the current value of the specified property is used. |
* (To search for null, you need to make sure that the |
* current property value is <code>null</code>, which is |
* the PHP default.) |
* @return array[Model]|null |
* Model objects, or <code>null</code> if there is no data |
* for this property and value |
* @see Table::select(Model) |
*/ |
public function findByProperty ($name, $value = null) |
{ |
$class = \get_class($this); |
$mapping = $class::getPersistentMapping(array($name)); |
|
if ($value === null) |
{ |
$value = $this->$name; |
} |
|
$results = $this->persistentTable->select(null, |
array($mapping[$name] => $value)); |
|
if ($results) |
{ |
return array_map(array($this, 'map'), $results); |
} |
|
return null; |
} |
|
/** |
* Saves the model object in the table |
* |
* @param array $propertyNames = null |