/** * Associate the given model. * * @param Record $instance * @return bool */ public function associate(Record $instance) { $instance->save(); $this->set(array($instance)); $this->parent->set($this->foreignKey, $instance->id()); return $this->parent->save(); }
/** * Count the number of related model instances. * * Counts loaded instances if they are present, queries storage otherwise. * * @return int */ public function count() { if (!$this->loaded()) { return $this->storage()->count($this->target->table(), $this->filter()); } return count($this->related); }
/** * Attach the registered storage to the ORM's active record class. * * @param Storage $storage */ public function boot(Storage $storage) { Record::setSharedStorage($storage); }