views:

55

answers:

1

I would have liked to know if it was a good idea to return a select object from a method like '$selectObj = getSomethingByName($name)' to then pass it to another method like 'getResult($selectObj)' which will do the trick. The idea is to be able to pass the select object to any usefull function like 'setLimit(10)' or addCriteria('blabla') depending on my model...

But is it a good idea to do this ? it could be 'unsecure' because user will be able to modify the object himself, and i should not want to this..

I used to do simple method before like above but returning the result as a row... but it's sometimes painfull when you have complex statement depending on different tables..

+4  A: 

The problem you are facing (complex statements depending on different tables) is an old and widespread problem with ORM frameworks in general. There are lots of things SQL can do, that an ORM doesn't do very well. Inevitably, you have to make up the different in complexity by writing lots of complicated code in your Controller or your View.

Instead, use a Domain Model pattern and encapsulate the complex multi-table database logic into one place, so your Controllers and Views don't have to know about all the sundry details. They just know about the interface of your Domain Model class, and that class has the sole responsibility to know how to fetch the information from the database.

Remember: a Model "HAS-A" table (or multiple tables) -- instead of Model "IS-A" table.

Bill Karwin