This might be a noob question, but I am not sure, what is the idiomatic way to do it.
I have two models:
-module(employee, [Id, PersonId, Company...]).
-belongs_to(person).
-module(person, [Id, Name, Bio...]).
I have a controller, that is returning only list of employees:
list('GET', [], _) ->
Employees = boss_db:find(employee, []).
{ok, [{employees, Employees}]}.
and in my template, I use something like this:
{{ employee.company }}
{{
employee.person.name }}
{{ employee.person.bio }}
[...]
I've found, that for every property in person table, I have one query to database for person record, so if person record has 6 properties to display, I have 6 additional queries for each employee.
For now, I just enabled caching. Is it the best way of solving this problem? Or maybe I should firstly get all employees and all people in my controller and then prepare structures for views? This also might be expensive, because for each employee, I would have to iterate over list of people.
Or maybe the best way would be to break the boss_db abstraction and use boss_db:execute directly on Postgres and use JOIN?