evanmsanders / flex2sms

Web front-end to SACFS flex2sms system.
1 stars 0 forks source link

Messages on contact view page should be in reverse chron. order #46

Closed mazzone closed 11 years ago

mazzone commented 11 years ago

The messages log on the contact view page currently shows all messages, ordered by id. Can we change it so that it orders them by id in reverse order, and also limit to say, 20 messages? Would also be good to change the query so it only returns the required fields too (id, text, processed).

mazzone commented 11 years ago

Evan assigned to this because I don't know how to do it. Hopefully I can copy what you do next time! :)

evanmsanders commented 11 years ago

Done. You can do this sort of thing by using what's called the 'containable behaviour', which basically allows you to tweak what data is returned when you load up a model.

You have to add

public $actsAs = array('Containable');

to the model file, and then tweak the find() call in the controller. Check out the changes for this commit to see what I mean. Basically, you can set up all the usual query conditions for each of the 'sub-queries' as well.

More info here: http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html