Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation discovery fails for pivot table #830

Closed
mgerzabek opened this issue Jun 14, 2024 · 2 comments
Closed

Navigation discovery fails for pivot table #830

mgerzabek opened this issue Jun 14, 2024 · 2 comments

Comments

@mgerzabek
Copy link
Contributor

mgerzabek commented Jun 14, 2024

Hi @27pchrisl,

I have a Premise model that is connected via a pivot table to a Customer model. On that model I have three relations:

#[LodataRelationship]
public function customers(): BelongsToMany {
    return $this->belongsToMany(Customer::class)
        ->using(CustomerPremise::class)
        ->withPivot(['valid_from', 'valid_to']);
}

#[LodataRelationship]
public function actual_customer(): BelongsToMany {
    return $this->customers()->wherePivot('valid_to', '=', '9999-12-31');
}

#[LodataRelationship]
public function customer_premises(): HasMany {
    return $this->hasMany(CustomerPremise::class);
}

The first two relationships are transformed into NavigationPropertyBindings:

<EntitySet Name="Customers" EntityType="io.pragmatiqu.Customer">
  <NavigationPropertyBinding Path="premises" Target="Premises"/>
  <NavigationPropertyBinding Path="actual_premises" Target="Premises"/>
  …
</>
…

The inverse relationships are on the Customer models side and have the same effect in $metadata.

However for the customer_premises() relationship, where direct access to the pivot table should be realized, is not transformed into a NavigationPropertyBinding.

The relationships on the pivot model CustomerPremise are:

#[LodataRelationship]
public function customer(): BelongsTo {
    return $this->belongsTo(Customer::class);
}

#[LodataRelationship]
public function premise(): BelongsTo {
    return $this->belongsTo(Premise::class);
}

When I try to access the binding, e.g. Premises(113)?$expand=customer_premises($expand=customer) I get the expanded customer but not the pivot.

Is this desired behaviour? Am I missing something?

How can I access properties on the pivot table?

Any hints welcomed.

@mgerzabek
Copy link
Contributor Author

mgerzabek commented Jun 14, 2024

The reason was that I did have no id column in the model.

@mgerzabek
Copy link
Contributor Author

After adding the id the relationship is detected and the NavigationPropertyBinding is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant