-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Allow multiple relationships on same table #1190
Allow multiple relationships on same table #1190
Conversation
In terms of the issue raised in your PR for searching/ordering when using a label/format, I do have a fix ready for a future release (not the pending one), which resolves the problem: As far as I know, the current workaround consists in configuring the column with the foreign key, and then formatting the column with the label or format column helper. For me, this has two problems:
But for the PR in general, it looks reasonable to me at first glance! For testing in general, I have been working on extending the test cases, and working on getting them to match the demo repo. This way, it'll all be a little more straight forward! I obviously haven't included this type of example yet! If you are willing to take a look at the Demo repo which is here: https://github.com/rappasoft/laravel-livewire-tables-demo, and are able come up with the model/relationships to demonstrate this, then I'll get it all incorporated into the next iteration of the test cases. Otherwise there'll be a slightly longer delay while I come up with it (currently I'm working on some AlpineJS functional migrations) I really, genuinely appreciate any/all contributions, and Anthony definitely does too! |
e70089b
to
6ddeb32
Compare
Hello @lrljoe, I've made a draft PR in the demo repo: rappasoft/laravel-livewire-tables-demo#30 I hope it is was what your were asking me to do. Please let me know if it was something else. On another subject, I was thinking about an edge case that should not be supported with this PR. I think we could have a colision with the aliases if we have:
|
Thanks, your PR looks fine at first glance, although it may cause some issues with existing components. I'll take a look this weekend and look at what needs doing to get it into a future release. It should make it into the release after the imminent one (which is just clean up and fixes).l Once I've had a proper look, I'll inevitably hassle you to produce some tests proving any backwards compatibility too, if you haven't already, or any docs adjustment explaining how it now works. For that edge case, it'll probably be simplest to shove the aliases into an array and append something to them if they already exist. But I'll have a play and see how it behaves. It may be the case that we stick in an option/configure method to enable this behaviour, but keep the current as default until v3, when we can make more sweeping changes to behaviour I'll let you know if that needs to be the case. Really appreciate the contribution! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
So on reviewing this, my main concern is that it'll be a breaking change for any existing components, as anyone using a relationship column will end up with it failing. What I'm definitely going to do however is introduce this change into the V3 upgrade which I've just started working on, which is an interim upgrade to make use of the Livewire V3 elements. |
@rappasoft - thoughts on adding this to v3 while we're at it? |
Lets give it a try |
Currently testing in v3.0a |
Just to make sure we don't merge this into v 2.0! It seems to work in v3.0, but would be a breaking change in 2.0 Will continue testing in 3.0 tho |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is in v3. and is on my backports radar l |
All Submissions:
New Feature Submissions:
Changes to Core Features:
Introduction
This pull request is an attempt to introduce the possibility to embed two relationships linked to the same table.
The problem is described in the issue #688. When we try to display two relationships linked to the same table, the first relation will be shown as the second relation too. As there is no alias, the second join is not applied because a join already exists on the target table.
As far as I know, the current workaround consists in configuring the column with the foreign key, and then formatting the column with the
label
orformat
column helper. For me, this has two problems:Proposed solution
This PR fix the problem by generating and adding an alias to the tables that are joined. The alias for the relations joins are generated by imploding the relation parts together and glueing them with an underscore.
Some examples:
I have a document class, with a sender and a producer, where both are a Sender
Table columns configuration:
Before the fix:
Generated query:
After the fix
Generated query:
Because the tables are now aliased, the joins are correctly handled by the
performJoin
method (at line 112).Breaking changes
If you provide a custom callback to
Column
searchable
function and you are specifying a table, you have to replace it by the alias.Example:
In the
tests/Http/Livewire/PetsTable.php
file at line55
, before the PR is merged:After the merge:
breeds.name
was replaced bybreed.name
TODO
Discussion
This is my first PR proposal, please let me know if I should change or improve something.
I'd appreciate some feedback about this feature, thank you.