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

[8.x] Columns in the order by list must be unique #37505

Closed
wants to merge 1 commit into from

Conversation

Javdu10
Copy link
Contributor

@Javdu10 Javdu10 commented May 27, 2021

In my application I have this kind of code:

    public function scopeEnabled(Builder $query)
    {
        return $query->where('is_enabled', true)->orderBy('position');
    }

    public function scopeParents(Builder $query)
    {
        return $query->whereNull('parent_id')->orderBy('position');
    }

Somewhere else I have : Model::scopes(['parents', 'enabled'])->first()

The SQL produced by this query is:
select * from models where parent_id is null and is_enabled = 1 order by position asc, position asc

This works in MySql however SQLServer complain saying:
A column has been specified more than once in the order by list. Columns in the order by list must be unique

You might say "Then just remove one orderBy() in either scope" however both are used independently.

I saw it happened to Nova see : laravel/nova-issues#1621

What I suggest is to make sure this cannot happen, let me know if I need to change anything!

MySql is ok with it, but SqlServer error out.
See a similar issue here: laravel/nova-issues#1621
@GrahamCampbell GrahamCampbell changed the title Columns in the order by list must be unique [8.x] Columns in the order by list must be unique May 27, 2021
@taylorotwell
Copy link
Member

Why wouldn't the last call take effect? Why not let it be overridable by calling order by again?

@Javdu10
Copy link
Contributor Author

Javdu10 commented May 31, 2021

@taylorotwell , this is an open question and I will shape it the way you want it, all it matters is that we have no duplicates when querying SQLServer

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.

2 participants