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

Handle dynamic model relations #5640

Merged
merged 5 commits into from
Aug 28, 2024
Merged

Handle dynamic model relations #5640

merged 5 commits into from
Aug 28, 2024

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Aug 28, 2024

WHY

Fixes #5635

BEFORE - What was wrong? What was happening before this PR?

We were not identifying dynamic relations on models.
Developers could do Model::resolveRelationUsing('something', fn($item) => $item->belongsTo()) and expect that CRUD::field('something') would work as if they were defining any other relationship field for relations that are explicitly defined on the model public function something() { return $this->belongsTo(); }

AFTER - What is happening after this PR?

We can properly identify dynamic relations on models. 🥳

HOW

How did you achieve that, in technical terms?

Changed the relevant functions that identify and work with relations to account for the fact that there might be dynamic relationships defined .

Is it a breaking change?

I don't think so, no. Tests are green, added more tests to account for this.

How can we test the before & after?

Define a dynamic relation on your model, and then try CRUD::field('relationName') and it won't work before this PR.

@pxpm pxpm merged commit c6b033e into main Aug 28, 2024
3 checks passed
@pxpm pxpm deleted the handle-dynamic-model-relations branch August 28, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug] relations field don`t work with resolveRelationUsing method
2 participants