I want to select 20 record in my database so I use this code to do that:
$query = Course::find()
->alias("t")
->select([
't.id', 't.subtitle', 't.title',
't.info', 't.skill_level_id', 't.special',
't.created', 't.modified', 't.price',
't.training_type_id', 't.media_id', 't.instructor_id',
't.extension_type'
])
->where(["t.deleted" => 0])
->joinWith([
'skillLevel', "courseTarget", "requirement", 'categoryCourses', "media",
"instructor", "trainingType"
]);
$query->limit(20);
return $query->all();
but this code will select just 5 records,
When I remove the joinWith
part, my code works fine and select 20 records.
Modified code:
$query = Course::find()
->alias("t")
->select([
't.id', 't.subtitle', 't.title',
't.info', 't.skill_level_id', 't.special',
't.created', 't.modified', 't.price',
't.training_type_id', 't.media_id', 't.instructor_id',
't.extension_type'
])
->where(["t.deleted" => 0]);
$query->limit(20);
return $query->all();
The modified code will return 20 records.
UPDATE1:
When I remove the limit(20)
it will return 496
records but when I added limit(20)
It just returns 5.
$query = Course::find()
->alias("t")
->select([
't.id', 't.subtitle', 't.title',
't.info', 't.skill_level_id', 't.special',
't.created', 't.modified', 't.price',
't.training_type_id', 't.media_id', 't.instructor_id',
't.extension_type'
])
->where(["t.deleted" => 0])
->joinWith([
'skillLevel', "courseTarget", "requirement", 'categoryCourses', "media",
"instructor", "trainingType"
]);
return $query->all()
This code works fine and returns everything but the limit()
query will made the response wrong