in this case what I want is just only count data form questions table, in table questions have a foreign key called questioncourse_id
anyone can help me to correct my code, please?
have you thought about using subqueries and ->join( …)
the subquery, provides countdata based on your keyfields.
$subquery: fetching countdata and fields to link
$query: joins the subquery plus all keyfields
add needed contains to it and check also enableAutoFields(true);
ps: you dont need a function for deeper associations or ? … you can either use just => […] or you use Dot-Notation. like QuestionCourses.Courses, QUestionCourses.QUestions. but check also your associations in your entity model for such cases usually you use the “through” link. - check the docs
sorry for “flat” reply, but maybe I update you with some real examples.