Forums

Count on another table

rafaelscouto 26 May, 2019
I have a loop function, with the data provider {var: read_info_people}.

In {var: read_info_people} I created a "History" Model, this Model takes information from another table in the database.

I need to return the count of how many stories you have in this table.
healyhatman 26 May, 2019
COUNT(model.fieldname):model.alias
rafaelscouto 26 May, 2019
How can I show this result in my loop?

Example of a db.
tb_people = id, name (Model = people)
(1, nameA),
(2, nameB),
(3, nameC);

tb_history = id, person_id, desc (Model = history)
(1, 1, 'desc001'),
(2, 1, 'desc002'),
(3, 1, 'desc003'),
(4, 1, 'desc004'),
(5, 2, 'desc005'),
(6, 2, 'desc006'),
(7, 3, 'desc007');

I need to display the quantity of person_id for each linked id.
healyhatman 27 May, 2019
In fields_to_retrieve
people.id
people.name
COUNT(history.id):people.count_of_stories

In Group By
people.id
in your loop
{var:loop#.row.people.count_of_stories}
This topic is locked and no more replies can be posted.