Voyager: HasOne and HasMany Relationships can only link to the Primary key of the child record.

Created on 12 Feb 2018  路  5Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.5.32
  • Voyager Version: 1.0.15
  • PHP Version: 7.0.23
  • Database Driver & Version: MySQL 5.7.19

I have the following Parent - Child table structure ....

Parent

  • id, primary key, Auto-Increment
  • name, string
  • child_id, integer

Child

  • id, primary key, Auto-Increment
  • name, string
  • parent_id, integer

The relationship is Parent HasOne/HasMany Child linked on Parent.child_id-->Child.parent_id

BREAD Relationships assume that the relationship is Parent.child_id -> Child.id

See relationship.blade.php, Line 48 ....

    @php 

        $relationshipData = (isset($data)) ? $data : $dataTypeContent;

        $model = app($options->model);

            $query = $model::where($options->column, '=', $relationshipData->id)->first();

    @endphp

But this is not always true.

Need some method to select an alternative child id

addressed enhancement

Most helpful comment

For us, this is a critical function. We would like to add Voyager to several existing third party apps, but there's no possibility that the database structure can be changed.

All 5 comments

Same issue for me.
谋 change manually
$query = $model::where($options->column, '=', $relationshipData->id)->first();
To
$query = $model::where($options->column, '=', $relationshipData->{$options->key})->first();

But this is not best solution.

I tested the same change and it does work :) , but really, this is just as inflexible as the current functionality.

IMO The Relationship configuration needs an additional parameter for the child table field_id.

This will likely not be fixed for 1.0.*

We're working on rebuilding the entire bread editor from scratch, so it'll function completely differently. I haven't decided whether that'll find it's way into 1.1, 1.2, or 2.0 yet

For us, this is a critical function. We would like to add Voyager to several existing third party apps, but there's no possibility that the database structure can be changed.

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wislem picture wislem  路  3Comments

MikadoInfo picture MikadoInfo  路  3Comments

IvanBohonosiuk picture IvanBohonosiuk  路  4Comments

raoasifraza1 picture raoasifraza1  路  3Comments

ferrywae picture ferrywae  路  4Comments