lithium\data\model\Query::model PHP Method

model() public method

Will also set the source table, i.e. $this->_config['source'] when setting the model.
public model ( string | null $model = null ) : string | Query
$model string | null Name of model to use, or `null` to retrieve current one.
return string | Query Either the current model name in use when $model is `null`, or the query itself when setting the model name.
    public function model($model = null)
    {
        if (!$model) {
            return $this->_config['model'];
        }
        $this->_config['model'] = $model;
        $this->_config['source'] = $this->_config['source'] ?: $model::meta('source');
        return $this;
    }

Usage Example

Example #1
0
 public function testModel()
 {
     $query = new Query($this->_queryArr);
     $this->assertEqual($this->_model, $query->model());
     $query->model('lithium\\tests\\mocks\\data\\model\\MockQueryComment');
     $expected = 'lithium\\tests\\mocks\\data\\model\\MockQueryComment';
     $result = $query->model();
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\data\model\Query::model