Subversion Repositories PHPX

Rev

Rev 55 | Rev 63 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55 Rev 62
Line 6... Line 6...
6
* Abstract model class for Object-Relational Mapping
6
* Abstract model class for Object-Relational Mapping
7
*
7
*
8
* Provides simple mapping of a model object to records of
8
* Provides simple mapping of a model object to records of
9
* a table of a relational database.
9
* a table of a relational database.
10
*
10
*
-
 
11
* @property Db\Table $persistentTable
11
* @author Thomas Lahn
12
* @author Thomas Lahn
12
*/
13
*/
13
abstract class Model extends \PointedEars\PHPX\AbstractModel
14
abstract class Model extends \PointedEars\PHPX\AbstractModel
14
{
15
{
15
  /**
16
  /**
Line 124... Line 125...
124
125
125
  /**
126
  /**
126
   * Finds the record for the model object in the table, fills
127
   * Finds the record for the model object in the table, fills
127
   * the object with missing data, and returns the result.
128
   * the object with missing data, and returns the result.
128
   *
129
   *
-
 
130
   * @param mixed $id = null
-
 
131
   *   The ID of the object to find.  If <code>null</code> (default),
-
 
132
   *   the object is search for by its current ID.
129
   * @see Table::find(Model)
133
   * @see Table::find(Model)
130
   * @return Model|null
134
   * @return Model|null
131
   *   This object filled with missing data, or <code>null</code>
135
   *   This object filled with missing data, or <code>null</code>
132
   *   if there is no data for this object
136
   *   if there is no data for this object
133
   */
137
   */
134
  public function find ()
138
  public function find ($id = null)
135
  {
139
  {
136
        $class = \get_class($this);
140
        $class = \get_class($this);
-
 
141
    if ($id !== null)
-
 
142
    {
-
 
143
      $this->{$class::$_persistentId} = $id;
-
 
144
    }
-
 
145
137
    $result = $this->persistentTable->find($this->{$class::$_persistentId});
146
    $result = $this->persistentTable->find($this->{$class::$_persistentId});
138
    if ($result)
147
    if ($result)
139
    {
148
    {
140
        return $this->map($result);
149
        return $this->map($result);
141
    }
150
    }
Line 149... Line 158...
149
   * @param array $propertyNames = null
158
   * @param array $propertyNames = null
150
   *   Names of the properties whose values should be saved
159
   *   Names of the properties whose values should be saved
151
   *   in the database.  The default is to save the values
160
   *   in the database.  The default is to save the values
152
   *   of all persistent properties.
161
   *   of all persistent properties.
153
   * @return boolean
162
   * @return boolean
-
 
163
   *   The return value of
-
 
164
   *   <code>$this->persistentTable->updateOrInsert()</code>.
154
   * @see Model::getPropertyArray()
165
   * @see Model::getPropertyArray()
155
   * @see Table::updateOrInsert()
166
   * @see Table::updateOrInsert()
156
   */
167
   */
157
  public function save (array $propertyNames = null)
168
  public function save (array $propertyNames = null)
158
  {
169
  {