D
D
Dilik Pulatov2017-05-29 10:05:05
Yii
Dilik Pulatov, 2017-05-29 10:05:05

In Yii2 how to get the number of elements using hasMany?

Hello!
For example, I have a category table and posts
when displaying a category should display the number of posts that are under this category
through HasMany how?
or is there another option? for example, through JOIN you can ... and how is it? (and JOIN is not when you did not make a request to get the amount)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-05-29
@dilikpulatov

To get the number of posts for one category, you can do this, for example,
If you need to get data for several categories, then you should do something like this (see the last example)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question