Skip to content

Commit

Permalink
Remove id key
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-invoiced committed Mar 23, 2023
1 parent 09d1ab2 commit fa6aee9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct(
?string $relation_type = null,
public readonly ?string $foreign_key = null,
public readonly ?string $local_key = null,
public readonly ?string $id_key = null,
public readonly ?string $pivot_tablename = null,
public readonly ?array $morphs_to = null,
?string $belongs_to = null,
Expand Down Expand Up @@ -114,7 +113,6 @@ public function toArray(): array
'relation_type' => $this->relation_type,
'foreign_key' => $this->foreign_key,
'local_key' => $this->local_key,
'id_key' => $this->id_key,
'pivot_tablename' => $this->pivot_tablename,
'morphs_to' => $this->morphs_to,
'enum_class' => $this->enum_class,
Expand Down
6 changes: 2 additions & 4 deletions src/Relation/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class BelongsToMany extends AbstractRelation
* @param string $foreignModel foreign model class
* @param string $foreignKey identifying key on foreign model
*/
public function __construct(Model $localModel, string $localKey, string $tablename, string $foreignModel, string $foreignKey, private readonly string|null $idKey)
public function __construct(Model $localModel, string $localKey, string $tablename, string $foreignModel, string $foreignKey)
{
$this->tablename = $tablename;

Expand All @@ -40,10 +40,8 @@ protected function initQuery(Query $query): Query
$pivot = new Pivot();
$pivot->setTablename($this->tablename);

$ids = $this->localModel->ids();
$ids = $this->idKey ? [$this->idKey => array_shift($ids)] : $ids ;
//known issue - this will work only on single join column
foreach ($ids as $idProperty => $id) {
foreach ($this->localModel->ids() as $idProperty => $id) {
if (null === $id) {
$this->empty = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Relation/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public static function make(Model $model, Property $property): AbstractRelation

if (self::BELONGS_TO_MANY == $type) {
$pivotTable = $property->pivot_tablename;
$idKey = $property->id_key;

return new BelongsToMany($model, $localKey, $pivotTable, $foreignModel, $foreignKey, $idKey);
return new BelongsToMany($model, $localKey, $pivotTable, $foreignModel, $foreignKey);
}

if (self::HAS_ONE == $type) {
Expand Down

0 comments on commit fa6aee9

Please sign in to comment.