Skip to content

Commit

Permalink
rewrite attach/morph queries to cope for saved data containing replac…
Browse files Browse the repository at this point in the history
…ed plugin models classes
  • Loading branch information
mjauvin committed Apr 22, 2021
1 parent eb489ff commit 745f205
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Database/Relations/AttachOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public function isPublic()
public function addConstraints()
{
if (static::$constraints) {
$this->query->where($this->morphType, $this->morphClass);
if (starts_with($this->morphClass, 'Winter\\')) {
$this->query->where(function ($q) {
$q->where($this->morphType, $this->morphClass);
$q->orWhere($this->morphType, str_replace('Winter\\', 'RainLab\\', $this->morphClass));
});
} else {
$this->query->where($this->morphType, $this->morphClass);
}

$this->query->where($this->foreignKey, '=', $this->getParentKey());

Expand Down
20 changes: 20 additions & 0 deletions src/Database/Relations/MorphOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ trait MorphOneOrMany
*/
protected $relationName;

/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
{
if (static::$constraints) {
if (starts_with($this->morphClass, 'Winter\\')) {
$this->query->where(function ($q) {
$q->where($this->morphType, $this->morphClass);
$q->orWhere($this->morphType, str_replace('Winter\\', 'RainLab\\', $this->morphClass));
});
} else {
$this->query->where($this->morphType, $this->morphClass);
}
}
}


/**
* Save the supplied related model with deferred binding support.
*/
Expand Down

0 comments on commit 745f205

Please sign in to comment.