laravel-livewire-tables icon indicating copy to clipboard operation
laravel-livewire-tables copied to clipboard

[Bug]: Undefined property: stdClass::$id when using select all checkbox

Open wimurk opened this issue 3 months ago • 4 comments

What happened?

image When clicking on the checkbox an error occurs

image

After investigating i came across this: In this function image

I noticed this function doesnt include the selects used in the columns method.

image

When using dd in the elequent method the response is: image

It misses all the columns i added in the columns section. image

How to reproduce the bug

No response

Package Version

latest

PHP Version

8.2.x

Laravel Version

10

Alpine Version

latest

Theme

Tailwind 3.x

Notes

No response

Error Message

Undefined property: stdClass::$id

wimurk avatar Mar 19 '24 11:03 wimurk

Make sure that you either have a column for the "id" field, or that it is added via setAdditionalSelects in your configure() method

lrljoe avatar Mar 23 '24 05:03 lrljoe

Make sure that you either have a column for the "id" field, or that it is added via setAdditionalSelects in your configure() method

I have the column set as primary key and i show it in the table.

wimurk avatar Mar 26 '24 09:03 wimurk

Same issue here. Also have an ID column visible on the table itself... so no need to setAdditionalSelects. This happens when I do $this->setAllSelected()

Update: I was able to resolve it by manually adding id to the query:

public function builder(): Builder
{
      return MyModel::query()->select(['id', 'col', ...]);
}

RishabSwift avatar Mar 27 '24 01:03 RishabSwift

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[bot] avatar Apr 26 '24 17:04 stale[bot]

You don't need to add the fields to the setAdditionalSelects so long as it's not a label() Column, if it is, then by design it doesn't add it inro the query.

Adding a select() method in your builder method may result in oddities, as it builds the query and selects the relevant fields internally.

lrljoe avatar May 02 '24 14:05 lrljoe