/** * Get the hydrated models without eager loading. * * @param array $columns * @return array */ public function getModels($columns = array()) { // First, we will simply get the raw results from the query builders which we // can use to populate an array with models. We will pass columns // that should be selected as well, which are typically just everything. $results = $this->query->get($columns); if ($this->total) { $this->total = $results->countAll(); } $connection = $this->model->getConnectionName(); $models = array(); // Once we have the results, we can spin through them and instantiate a fresh // model instance for each records we retrieved from the database. We will // also set the proper connection name for the model after we create it. foreach ($results as $result) { $models[] = $model = $this->model->newFromBuilder($result); $model->setConnection($connection); } return $models; }
/** * Get the name of the related model's "updated at" column. * * @return string */ public function relatedUpdatedAt() { return $this->related->getUpdatedAtColumn(); }
/** * Save a new model and attach it to the parent model. * * @param \LMongo\Eloquent\Model $model * @return \LMongo\Eloquent\Model */ public function save(Model $model) { $model->save(); $this->attach($model); return $model; }
/** * Associate the model instance to the given parent. * * @param \LMongo\Eloquent\Model $model * @return \LMongo\Eloquent\Model */ public function associate(Model $model) { $this->parent->setAttribute($this->foreignKey, $model->getKey()); return $this->parent->setRelation($this->relation, $model); }
/** * Saves the model instance to database. If necessary, it will purge the model attributes * of unnecessary fields. It will also replace plain-text password fields with their hashes. * * @param array $options * @return bool */ protected function performSave(array $options) { if ($this->autoPurgeRedundantAttributes) { $this->attributes = $this->purgeArray($this->attributes); } if ($this->autoHashPasswordAttributes) { $this->attributes = $this->hashPasswordAttributes($this->attributes, static::$passwordAttributes); } return parent::save($options); }
/** * Bootstrap the application events. * * @return void */ public function boot() { Model::setConnectionResolver($this->app['lmongo']); Model::setEventDispatcher($this->app['events']); }
/** * Attach a model instance to the parent model. * * @param \LMongo\Eloquent\Model $model * @return \LMongo\Eloquent\Model */ public function save(Model $model) { $model->setAttribute($this->foreignKey, new MongoID($this->parent->getKey())); return $model->save() ? $model : false; }
/** * Set a model instance for the model being queried. * * @param \LMongo\Eloquent\Model $model * @return \LMongo\Eloquent\Builder */ public function setModel(Model $model) { $this->model = $model; $this->query->collection($model->getCollection()); return $this; }
/** * Attach a model instance to the parent model. * * @param \LMongo\Eloquent\Model $model * @return \LMongo\Eloquent\Model */ public function save(Model $model) { $model->setAttribute($this->morphType, $this->morphClass); return parent::save($model); }
/** * Get the name of the "updated at" column. * * @return string */ public function updatedAt() { return $this->parent->getUpdatedAtColumn(); }