orderBy works, even though column does not exist

Posted 6 months ago by MikeHopley

I think I'm missing something really obvious here. Take this simple controller code:

public function getFreePages()
{
    return FreePage::orderBy('order')->get();
}

I removed the "order" column from the table, but forgot about it. Despite this, the code still "works" on my local development site -- it's returning a JSON collection, even though the "order" property does not exist.

It also works on my remote testing site -- but not in production, which gives the "column not found" error you would expect. The production site is on the same server as the testing site.

On the local site, I can change the column name to anything at all, and it still works:

public function getFreePages()
{
    return FreePage::orderBy('this-column-never-existed-for-sure')->get();
}

Please sign in or create an account to participate in this conversation.