Skip to content

Commit

Permalink
Fixes foundation classes
Browse files Browse the repository at this point in the history
This restores the previous functionality broken by the previous team

Refs octobercms/october#5542
  • Loading branch information
daftspunk committed Mar 23, 2021
1 parent 2be8b61 commit a0d8a73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 353 deletions.
14 changes: 9 additions & 5 deletions src/Database/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ public function attach($id, array $attributes = [], $touch = true)
return;
}

/**
* @see Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable
*/
parent::attach($id, $attributes, $touch);
// Here we will insert the attachment records into the pivot table. Once we have
// inserted the records, we will touch the relationships if necessary and the
// function will return. We can parse the IDs before inserting the records.
$this->newPivotStatement()->insert($insertData);

if ($touch) {
$this->touchIfTouching();
}

/**
* @event model.relation.afterAttach
Expand All @@ -172,7 +176,7 @@ public function detach($ids = null, $touch = true)
{
$attachedIdList = $this->parseIds($ids);
if (empty($attachedIdList)) {
$attachedIdList = $this->allRelatedIds()->all();
$attachedIdList = $this->newPivotQuery()->lists($this->relatedPivotKey);
}

/**
Expand Down
22 changes: 0 additions & 22 deletions src/Database/Relations/DefinedConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,4 @@ public function addDefinedConstraintsToQuery($query, $args = null)
$query->$scope($this->parent);
}
}

/**
* Create a new query builder for the pivot table.
*
* This is an extension of Laravel's `newPivotQuery` method that allows `belongsToMany` and `morphToMany` relations
* to have conditions.
*
* @return \Illuminate\Database\Query\Builder
*/
public function newPivotQuery()
{
$query = parent::newPivotQuery();

// add relation's conditions and scopes to the query
$this->addDefinedConstraintsToQuery($query);

$related = $this->getRelated();

return $query
->join($related->getTable(), $related->getQualifiedKeyName(), '=', $this->getOtherKey())
->select($this->getTable().'.*');
}
}
326 changes: 0 additions & 326 deletions tests/Database/RelationsTest.php

This file was deleted.

0 comments on commit a0d8a73

Please sign in to comment.