[web2py] Re: query DAL

2014-05-01 Thread Brian M
The database view trick would work. Or how about adding a "current" flag and whenever you do a situation update/insert you set the new record's current flag to true and those of all that person's other situation records to false. You could either do it in web2py or with a database trigger. Seems

[web2py] Re: query DAL

2014-04-30 Thread Joe Barnhart
You could create a view of the table "Situation" which groups by id_person and returns max(id_status). Then you can do a normal join using the view to establish the relationship between the other two tables. You can have a view in web2py by creating the table as normal, but marking it as migra

[web2py] Re: query DAL

2014-04-29 Thread Fernando Vieira
Yes I have id_situation field but do not know the sub query. The idea is to catch the last id_sutation person in a subquery In SQL I managed to make fast SELECT DISTINCT ON (p.name) p.name, (SELECT s.id_status from situation where s.id_person = p.id order by id desc limit 1) as status from per