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?

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/5c5b06e1-2555-41b6-9c8e-6c2fd24b4a9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to