Skip to content

Conversation

@FiloSpaTeam
Copy link

@FiloSpaTeam FiloSpaTeam commented Feb 6, 2024

You can sort things like this:
image

EDIT: The array in this position seems needed to filters with dates so reverted.

@guillaumebriday
Copy link
Owner

Hi! Thanks for the PR 🙌

Can you describe what you're trying to achieve here in the PR's description?

thank

@FiloSpaTeam FiloSpaTeam changed the title fix and new feature. Sortable fields with scope:name_of_scope Mar 5, 2024
FiloSpaTeam and others added 4 commits July 11, 2024 10:36
…ion is polymorphic (#2)

Keeps using `allowed_includes` but applies `preload` when the relation
is polymorphic in order to overcome
`ActiveRecord::EagerLoadPolymorphicError: Cannot eagerly load the
polymorphic association xxx`.
Could be improved but had to rush to fix a regression
When no `default_sort` is defined for the target class, doesn't remove
previously defined query conditions.

Before this change:

```ruby
MyModel.where(id: 3).apply_sort({})
```

`apply_sort` would remove `where(id: 3)` when `MyModel` doesn't include
the definition of `default_sort`.

This was happening because the empty behavior were returning the model
class instead of an ActiveRecord relation based on the same class,
therefore beaking the scopes chaining.

With this change, the returned object is an ActiveRecord relation even
when no `default_sort` is defined.
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

Successfully merging this pull request may close these issues.

3 participants