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

Add support for MorphOne relationships #844

Merged
merged 2 commits into from
Jan 17, 2023
Merged

Add support for MorphOne relationships #844

merged 2 commits into from
Jan 17, 2023

Conversation

DanielGSoftware
Copy link
Contributor

@DanielGSoftware DanielGSoftware commented Jul 14, 2022

Take the following relationship
Model Address, which has a morphTo() method and has addressable_id and addressable_type columns.
Model User , which has MorphOne() that points to the address model.

If I have a user table, and I want to display the street of the address, I would do Column::make('street', 'address.street').

This will give the following exception: Rappasoft\LaravelLivewireTables\Views\Column::setTable(): Argument #1 ($table) must be of type string, null given, called in /Users/danielgebben/Documents/LenderSpender/platform/vendor/rappasoft/laravel-livewire-tables/src/Traits/Helpers/ColumnHelpers.php on line 24.

This is because MorphOne is not supported when making the columns.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests and did you add any new tests needed for your feature?
  2. Did you update all templates (if applicable)?
  3. Did you add the relevant documentation (if applicable)?
  4. Did you test locally to make sure your feature works as intended? Yes

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
    Not yet, I'd first like this to pass and then I'll add tests
  • Have you successfully ran tests with your changes locally?

@stale
Copy link

stale bot commented Oct 1, 2022

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.

@stale stale bot added the wontfix This will not be worked on label Oct 1, 2022
@stale stale bot closed this Oct 8, 2022
@rappasoft rappasoft reopened this Oct 9, 2022
@stale stale bot removed the wontfix This will not be worked on label Oct 9, 2022
@stale
Copy link

stale bot commented Nov 9, 2022

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.

@stale stale bot added the wontfix This will not be worked on label Nov 9, 2022
@stale stale bot closed this Nov 16, 2022
@DanielGSoftware
Copy link
Contributor Author

Reopen, I still think this is relevant.

@rappasoft rappasoft reopened this Nov 24, 2022
@stale stale bot removed the wontfix This will not be worked on label Nov 24, 2022
@hasan-ozbey
Copy link

thank you so much for finding this, you saved my day

@Francesco-Cirillo
Copy link

thank you for the change.
I need it in my web project, but I don't want to edit my vendor directory: I have to wait he pull request will be accepted?

@KSneijders
Copy link

KSneijders commented Dec 19, 2022

Just manually applied the small changes to test and it works flawlessly! Thanks @DanielGSoftware! ❤️

@rappasoft What is necessary for this to be merged?

Edit: Actually, whilst it does solve the error and retrieves the data, the sorting itself doesn't seem to work
Edit2: I've created an issue ( #987 ) that potentially found the issue for the sorting problem

@KSneijders
Copy link

For anyone finding this, you can (as temporary solution) copy the version from this Pull Request into a new file.
For example: App\Traits\WithData. Make sure to change the namespace at the top to: namespace App\Traits;

Then go to the AppServiceProvider and add the following line as imports:

use Rappasoft\LaravelLivewireTables\Traits\WithData;
use App\Traits\WithData as WithDataFixedUnsupportedMorph;

And add the following in the register function:

$loader = AliasLoader::getInstance();
$loader->alias(WithData::class, WithDataFixedUnsupportedMorph::class);

( @Francesco-Cirillo )

@lrljoe
Copy link
Collaborator

lrljoe commented Jan 16, 2023

Tested against core, all appears working @rappasoft - this seems okay to commit

@rappasoft rappasoft added the Awaiting Next Release Currently merged into development awaiting a release to master label Jan 17, 2023
@rappasoft rappasoft mentioned this pull request Jan 17, 2023
@rappasoft rappasoft merged commit a337555 into rappasoft:master Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Next Release Currently merged into development awaiting a release to master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants