|
@@ 660-671 (lines=12) @@
|
| 657 |
|
* @throws MappingException |
| 658 |
|
* @return \Analogue\ORM\Relationships\HasOne |
| 659 |
|
*/ |
| 660 |
|
public function hasOne($entity, $relatedClass, $foreignKey = null, $localKey = null) |
| 661 |
|
{ |
| 662 |
|
$foreignKey = $foreignKey ?: $this->getForeignKey(); |
| 663 |
|
|
| 664 |
|
$relatedMapper = $this->manager->mapper($relatedClass); |
| 665 |
|
|
| 666 |
|
$relatedMap = $relatedMapper->getEntityMap(); |
| 667 |
|
|
| 668 |
|
$localKey = $localKey ?: $this->getKeyName(); |
| 669 |
|
|
| 670 |
|
return new HasOne($relatedMapper, $entity, $relatedMap->getTable() . '.' . $foreignKey, $localKey); |
| 671 |
|
} |
| 672 |
|
|
| 673 |
|
/** |
| 674 |
|
* Define a polymorphic one-to-one relationship. |
|
@@ 796-807 (lines=12) @@
|
| 793 |
|
* @throws MappingException |
| 794 |
|
* @return \Analogue\ORM\Relationships\HasMany |
| 795 |
|
*/ |
| 796 |
|
public function hasMany($entity, $related, $foreignKey = null, $localKey = null) |
| 797 |
|
{ |
| 798 |
|
$foreignKey = $foreignKey ?: $this->getForeignKey(); |
| 799 |
|
|
| 800 |
|
$relatedMapper = $this->manager->mapper($related); |
| 801 |
|
|
| 802 |
|
$table = $relatedMapper->getEntityMap()->getTable() . '.' . $foreignKey; |
| 803 |
|
|
| 804 |
|
$localKey = $localKey ?: $this->getKeyName(); |
| 805 |
|
|
| 806 |
|
return new HasMany($relatedMapper, $entity, $table, $localKey); |
| 807 |
|
} |
| 808 |
|
|
| 809 |
|
/** |
| 810 |
|
* Define a has-many-through relationship. |