Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Added support for polymorphic many-to-many relationships #232

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/LaravelBook/Ardent/Ardent.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ abstract class Ardent extends Model {
* @see \Illuminate\Database\Eloquent\Model::morphTo
* @see \Illuminate\Database\Eloquent\Model::morphOne
* @see \Illuminate\Database\Eloquent\Model::morphMany
* @see \Illuminate\Database\Eloquent\Model::morphToMany
* @see \Illuminate\Database\Eloquent\Model::morphedByMany
*
* @var array
*/
Expand All @@ -190,6 +192,10 @@ abstract class Ardent extends Model {

const MORPH_MANY = 'morphMany';

const MORPH_TO_MANY = 'morphToMany';

const MORPHED_BY_MANY = 'morphedByMany';

/**
* Array of relations used to verify arguments used in the {@link $relationsData}
*
Expand All @@ -198,7 +204,8 @@ abstract class Ardent extends Model {
protected static $relationTypes = array(
self::HAS_ONE, self::HAS_MANY,
self::BELONGS_TO, self::BELONGS_TO_MANY,
self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY
self::MORPH_TO, self::MORPH_ONE, self::MORPH_MANY,
self::MORPH_TO_MANY, self::MORPHED_BY_MANY
);

/**
Expand Down Expand Up @@ -339,6 +346,8 @@ protected function handleRelationalArray($relationName) {

case self::MORPH_ONE:
case self::MORPH_MANY:
case self::MORPH_TO_MANY:
case self::MORPHED_BY_MANY:
$verifyArgs(array('type', 'id'), array('name'));
return $this->$relationType($relation[1], $relation['name'], $relation['type'], $relation['id']);
}
Expand Down