collectiveidea / awesome_nested_set

An awesome replacement for acts_as_nested_set and better_nested_set.
MIT License
2.39k stars 491 forks source link

Make order_column option more flexible #451

Closed Kulgar closed 3 years ago

Kulgar commented 3 years ago

Hello everyone,

I'm doing this little pull request to address a limitation I faced using the gem.

Indeed, I have a "jsonb" column that stores translations like this in my model "Tag" that uses this gem: label_i18n: { en: "Label", fr: "Sujet" }

I wanted to sort the children of tags like this:

SELECT "tags".* FROM "tags" ORDER BY ("tags"."label_i18n" ->> 'fr') ASC

But I can't do that with the current options as you are forcing the "=> :asc" part.

So... as the "=> :asc" is implicit when you don't specify it, I was just thinking: why not removing it so that the order_column option can accept more complexe options?

I added a spec to test a more complexe option: { :name => :desc } which is a more common usecase than mine I think.

Thanks in advance for any feedbacks!

stale[bot] commented 3 years ago

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.

Kulgar commented 3 years ago

No feedbacks on my PR?

parndt commented 3 years ago

Thanks @Kulgar it's great 😄

Kulgar commented 3 years ago

@parndt : thank you for reviewing and accepting my PR :-)