Closed andrersilva96 closed 1 year ago
Couple very quick question before I take a look in the next day or two -
Are the Database:
Are you using the Builder() approach or just a model name specified?
Have you added all of the relevant IDs into your setAdditionalSelects in the configure method, where you're not using them in a column?
Sorry take too long.
And this is the query generated:
SELECT
`matches`.`id` AS `id`,
`properties`.`id` AS `propertyFrom.id`,
`properties`.`id` AS `propertyTo.id`,
`matches`.`created_at` AS `created_at`
FROM
`matches`
LEFT JOIN
`properties` ON `matches`.`property_id_from` = `properties`.`id`
LIMIT 25 OFFSET 0
Solution:
To my column I called the label function and did something like:
->label(function ($row) use ($data) {
$value = null;
foreach (explode('.', $data['column']) as $attr) {
$value = !$value ? $row->{$attr} : $value->{$attr};
}
return $value;
});
So in column I can call like "id" or "user.profile.name".
Glad you were able to fix it, but I'd definitely check your queries as you're possibly introducing multiple queries with your approach.
I'm a bit confused as to why you're checking if the model table is users in your Builder function, as you should surely know if it is or not when you create the Component...
You can use the following in your configure() method to add more fields that you're not directly referencing as columns, and then you'll be able to reference them as $row->fieldName, or whatever you choose.
$this->setAdditionalSelects(['someTable.someColumnName as fieldName']);
Thank you for helping, about the checking if the model table is users its because functionality of my system, instead of having several models of datatables I only have one and I pass the configuration with the model and the columns that I want in an array
Why not use a trait instead out of interest?
Otherwise if you're passing in things like columns as a variable, you run the risk of exposing something you don't want to to a malicious user.
It because I use the nwidart modules, so each client it's a different configuration array and the user doesn't has access.
As long as they're protected/private variables in your component then! If they're anything else, then the user will have access unless you're using another mechanism to protect the variable.
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.
Just a quick note, I believe this is now fixed in v3.0, so I'd welcome your test when it comes to the beta in a week or two.
@andrersilva96 - The V3 Beta is out, if you're able to test it (it's Livewire 3.0+) then that'd be great, I can then look at backporting anything that isn't a breaking change into v2.
What happened?
Duplicate value from different relationship but seeing the same table.
How to reproduce the bug
In a class/child table that has parent relationship, for example my class Matcher:
My datatable class has these columns:
The result:
As you can see in database:
The properties table:
I won't to show the users table because is the same id from profiles table ok... so this is the profiles table:
The result should be:
Package Version
2.14.0
PHP Version
8.1.x
Laravel Version
9
Alpine Version
3.10.5
Theme
Bootstrap 5.x
Notes
The result is the same for different relationship with same table, in the other words parent_id_from and parent_id_to for same table.
And Yes I've consulted your documentation: https://rappasoft.com/docs/laravel-livewire-tables/v2/columns/relationships
Error Message
None error.