Column Not Found In Cdbcriteria Join

Hi,

So I thought I would have cracked my problem when reading this following post. I’ve compared this query to mine below … but I’m still getting Unknown column ‘EntrySubject.subject_id’. What am I doing wring folks?


		$subjectEntries = new CDbCriteria();

		$subjectEntries->alias = 'EntrySubject';

		$subjectEntries->join = 'INNER JOIN Subject ON Subject.id = EntrySubject.subject_id';

		$subjectEntries->select = 'EntrySubject.id, EntrySubject.subject_id';

		$subjectEntries->condition = 'Subject.id='.$id;

		$subjectEntriesModel=Subject::model()->findAll($subjectEntries); 


$subjectEntries->join = 'INNER JOIN Subject'

Subject::model()->findAll($subjectEntries)

Seems like you’re joining Subject with Subject, is that by purpose?

definitely not. here’s my original SQL … am I getting myself confused?


SELECT entry_subject.id, entry_subject.subject_id FROM entry_subject INNER JOIN subject ON entry_subject.subject_id = subject.id WHERE subject.id = 71

I suppose you should use either EntrySubject::model()->findAll or $subjectEntries->join = ‘INNER JOIN entry_subject’, depending on what you really need.