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

Undefined property: stdClass::$role.id_role (select -> table.column) #6

Closed
renmura opened this issue Aug 21, 2021 · 4 comments
Closed

Comments

@renmura
Copy link

renmura commented Aug 21, 2021

Hi, I read the documentation here about join query.
I have two simple table to join with. But there is an error says that Undefined property: stdClass::$role.id_role
Somehow the library recognize the table name as the column name, including the period symbol.
In the documentation says that the offices.officeCode is fine.

Here is my code :

User table structure :
id_user*
id_role**
name

Role table structure :
id_role*
role_name

Controller :
$builder = $db->table('user')
->select('name, role.id_role, role.role_name')
->join('role', 'role.id_role = user.id_role');

return DataTable::of($builder)
->addNumbering()
->toJson(true);

Error :
ErrorException
Undefined property: stdClass::$role.id_role
VENDORPATH/hermawan/codeigniter4-datatables/src/DataTableQuery.php at line 101

@hermawanramadhan
Copy link
Owner

can you show your javascript code?

what php and codeigniter version do you use?

@renmura
Copy link
Author

renmura commented Aug 22, 2021

can you show your javascript code?

what php and codeigniter version do you use?

I'm using php 8.0 and codeigniter 4.1.3
here is my javascript :

$('#table').DataTable({
processing: true,
serverSide: true,
ajax:{
url: 'user/datatable',
method: 'POST'
},
columnDefs: [
{ targets: 0, orderable: false}, //first column is not orderable.
],
sDom: "<'row'<'col-md-4'l><'col-md-4'B><'col-md-4'f>r>t<'row'<'col-md-6'i><'col-md-6'p>>",
buttons: [
'copy',
{
extend: 'excel',
orientation: 'landscape',
pageSize: 'A4',
},
{
extend: 'pdf',
orientation: 'landscape',
pageSize: 'A4',
},
{
extend: 'print',
orientation: 'landscape',
pageSize: 'A4',
}
]
});

@hermawanramadhan
Copy link
Owner

try define your datatable option with columns like example. also if using numbering also set parameter addNumbering('number');

in your case maybe like this

columns: [
    {data: 'number'},
    {data: 'id_role'},
    {data: 'role_name'},
]

@renmura
Copy link
Author

renmura commented Aug 22, 2021

try define your datatable option with columns like example. also if using numbering also set parameter addNumbering('number');

in your case maybe like this

columns: [
    {data: 'number'},
    {data: 'id_role'},
    {data: 'role_name'},
]

Great, it works.. I think the error from before is come from the backend side not in the frontend side..
Thank you very much

@renmura renmura closed this as completed Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants