Also bit more information, if I misspell a column it gives me the SQL in the error …
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘job_role_competences.sort_order’ in ‘order clause’. The SQL statement executed was: SELECT t.id AS t0_c0, t.fk_id_with_competency_id_field AS t0_c1, t.fk_id_with_job_title_id_field AS t0_c2, t.fk_id_with_competency_level_id_field AS t0_c3, t.deleted AS t0_c4, t.created_date AS t0_c5, t.updated_date AS t0_c6, t.created_user_id AS t0_c7, t.updated_user_id AS t0_c8, job_title.id AS t1_c0, job_title.fk_id_with_job_role_id_field AS t1_c1, job_title.name AS t1_c2, job_title.sort_order AS t1_c3, job_title.deleted AS t1_c4, job_title.created_date AS t1_c5, job_title.updated_date AS t1_c6, job_title.created_user_id AS t1_c7, job_title.updated_user_id AS t1_c8, job_role.id AS t2_c0, job_role.fk_id_with_job_family_id_field AS t2_c1, job_role.name AS t2_c2, job_role.deleted AS t2_c3, job_role.created_date AS t2_c4, job_role.updated_date AS t2_c5, job_role.created_user_id AS t2_c6, job_role.updated_user_id AS t2_c7, job_role_competencies.id AS t3_c0, job_role_competencies.fk_id_with_competency_id_field AS t3_c1, job_role_competencies.fk_id_with_job_role_id_field AS t3_c2, job_role_competencies.sort_order AS t3_c3, job_role_competencies.deleted AS t3_c4, job_role_competencies.created_date AS t3_c5, job_role_competencies.updated_date AS t3_c6, job_role_competencies.created_user_id AS t3_c7, job_role_competencies.updated_user_id AS t3_c8 FROM CompetencyRequiredLevelt LEFT OUTER JOIN JobTitlejob_title ON (t.fk_id_with_job_title_id_field=job_title.id) AND (job_title.deleted = ‘no’) LEFT OUTER JOIN JobRolejob_role ON (job_title.fk_id_with_job_role_id_field=job_role.id) AND (job_role.deleted = ‘no’) LEFT OUTER JOIN JobRoleCompetencyjob_role_competencies ON (job_role_competencies.fk_id_with_job_role_id_field=job_role.id) AND (job_role_competencies.deleted = ‘no’) WHERE ((t.deleted = ‘no’) AND (fk_id_with_job_title_id_field = ‘61’)) ORDER BY job_role_competences.sort_order LIMIT 10 (/home/lucomdev/yii/framework/db/CDbCommand.php:541)
I have also tried t3_c3 which is suppose to the job_role_competencies.sort_order but still nothing.
First, what is this belongsToJobTitle() function that you’ve used? It should return a model finder instance instead of actually perfoming any query to the db, make sure it really does that.
Second, it’s better to put the with() in the the criteria too, try this: