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

Failed to Acces Relation #6

Closed
zendzo opened this issue Sep 13, 2018 · 3 comments
Closed

Failed to Acces Relation #6

zendzo opened this issue Sep 13, 2018 · 3 comments

Comments

@zendzo
Copy link

zendzo commented Sep 13, 2018

i have 3 relations

user ->hasOne->room
room->belongsTo->floor
floor->hasMany->room

{ name: 'id' },
{ name: 'name' },
{ name: 'email' },
{ name: 'action', orderable: false, searchable: false },
{ name: 'room.name', orderable: false },
{ name: "room.floor.level" } // this show [object Object] on the table
@zendzo
Copy link
Author

zendzo commented Sep 13, 2018

i get the value of floor level by defining custom column
but it is possible if i want to access floor level through room.floor.level i think this is simpler

public static function laratablesCustomLevel($user)
    {
        return $user->room->floor->level;
    }
columns: [
                  { name: 'id' },
                  { name: 'name' },
                  { name: 'email' },
                  { name: 'action', orderable: false, searchable: false },
                  { name: 'room.name', orderable: false },
                  { name: 'level' }
              ]

@gauravmak
Copy link
Member

You're right @zendzo

Nested relationships aren't supported yet.

You have used the custom column the right way but you should also tell the query to eager load data to prevent n+1 issue.

/**
 * Specify additional conditions for the query, if any.
 *
 * @param \Illuminate\Database\Eloquent\Builder
 * @param \Illuminate\Database\Eloquent\Builder
 */
public static function laratablesQueryConditions($query)
{
    return $query->with([ 'room.floor.level' ]);
}

@gauravmak
Copy link
Member

As this isn't a common use case, I would prefer not to add support for now. Have already added the note in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants