Ejemplo n.º 1
0
 /**
  * Define a polymorphic many-to-many relationship.
  *
  * @param  string $related
  * @param  string $name
  * @param  string $table
  * @param  string $foreignKey
  * @param  string $otherKey
  * @param  bool $inverse
  * @return \Analogue\ORM\Relationships\MorphToMany
  */
 public function morphToMany($entity, $related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false)
 {
     $caller = $this->getBelongsToManyCaller();
     // First, we will need to determine the foreign key and "other key" for the
     // relationship. Once we have determined the keys we will make the query
     // instances, as well as the relationship instances we need for these.
     $foreignKey = $foreignKey ?: $name . '_id';
     $relatedMapper = $this->manager->mapper($related);
     $otherKey = $otherKey ?: $relatedMapper->getEntityMap()->getForeignKey();
     $table = $table ?: str_plural($name);
     return new MorphToMany($relatedMapper, $entity, $name, $table, $foreignKey, $otherKey, $caller, $inverse);
 }
 /**
  * Instantiate an user entity
  *
  * @return User
  */
 private function getEntity()
 {
     $entity = $this->getEntity();
     return $this->manager->mapper($entity)->newInstance();
 }
Ejemplo n.º 3
0
 /**
  * Create a mapper for a given entity (static alias)
  *
  * @param \Analogue\ORM\Mappable|string $entity
  * @param mixed $entityMap
  * @return Mapper
  */
 public static function getMapper($entity, $entityMap = null)
 {
     return static::$instance->mapper($entity, $entityMap);
 }