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

Cant figure out how to get this package to work #4

Open
timcv opened this issue Feb 6, 2020 · 3 comments
Open

Cant figure out how to get this package to work #4

timcv opened this issue Feb 6, 2020 · 3 comments

Comments

@timcv
Copy link

timcv commented Feb 6, 2020

I have added to my resource:

public static $sortRelations = [
        'dealer'          => 'dealers.name',
    ];

When i click the column for my belongs to field the key inte url is set to 'dealer_id'.

This mean that that the array_key_exists in the foreach in applyOrderings will search for a column named 'delaer_id' while my array key in $sortRelations is set to 'dealer'.

I understand that i need to modify the index query and join the dealer table to my resource.

Do you have any idea about what im missing?
Is this suposed to work with belongsTo fields?

@RVxLab
Copy link

RVxLab commented Aug 27, 2020

@timcv

Not sure if my comment is still relevant here.

The key in the $sortRelations array is the name of the relation you're trying to sort on and the value is the column of that relation. If you then join the table in indexQuery it should work.

If that doesn't work you may need to provide more info.

And yes, it works with BelongsTo fields.

@bilogic
Copy link

bilogic commented Aug 10, 2021

@RVxLab does not seem to work, I have a products.color_id, trying to sort by colors's name.
I have a function color() in Product.php model but the SQL is invalid. What did I do wrong?

public static $sortRelations = [
    'color' => 'colors.name',    // doesn't sort by name, it sorts by color_id only
];
# generates invalid SQL
select * from `products` order by `colors`.`name` desc limit 26 offset 0          

@bilogic
Copy link

bilogic commented Aug 10, 2021

@timcv I had to join the colors table myself inside indexQuery(). Works now, but I was expecting something easier. Thanks anyway @RVxLab

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

3 participants