Welcome Guest, Not a member yet? Register   Sign In
Limit returning rows in Model or Controller? Recommendation
#1

[eluser]bunal[/eluser]
Hi,

Which way do you prefer in models?

a) Return all records and limit/paginate them in controller?

Code:
MODEL:
function getInvoices(){

}

b) Return limited records?

Code:
MODEL:
function getInvoices($offset=0, $limit=100){

}
#2

[eluser]Phil Sturgeon[/eluser]
If you limit in the controller then you must be returning ALL records then array_slicing the ones you want? That is bad mojo dude.

Always limit in the model with a param passed in from the controller. They have another method to count how many results there are in total. Much cleaner. :-)
#3

[eluser]bunal[/eluser]
Thanks Phil Wink
#4

[eluser]mattpointblank[/eluser]
It always annoys me that when paginating, I STILL have to fetch all the records, to do the count. I know there's no other way around it, but 2 queries for each dataset is a pain.




Theme © iAndrew 2016 - Forum software by © MyBB