CodeIgniter Forums
Unknown column in order clause - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Unknown column in order clause (/thread-73969.html)



Unknown column in order clause - antoniocapuozzo - 07-01-2019

Hello everyone! 

I've a problem returning the first row of the result set with the first() method (i suppose).


PHP Code:
Unknown column 'games.id' in 'order clause' 

This is the Migration
[attachment=1580]

This is the GamesModel
[attachment=1581]

This is the Games Controller
[attachment=1582]

If a change the id filed in "id" everything works fine. 

Does It is a convention to follow?

If yes, how can i bypass this behaviour?

Thank you all. 

PS Version 4 is awesome! Great work.


RE: Unknown column in order clause - includebeer - 07-01-2019

I think you just need to tell CI the name of your primary key. The default is “id” when you don’t set a specific name: https://codeigniter4.github.io/userguide/models/model.html#configuring-your-model

PHP Code:
protected $primaryKey 'game_id'



RE: Unknown column in order clause - antoniocapuozzo - 07-01-2019

Oh sure. I'm a complete fool! It's working as it should now.

Thanks you so much for the reply and the link too!