What do you think of returning a select object instead of the result of the statement?

I would like to know if it was a good idea to return a select object from a method like $ selectObj = getSomethingByName ($ name) 'to 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 useful function like setLimit (10) 'or addCriteria (' blabla ') depending on my model ...

But is it worth doing? it might be "unsafe" because the user will be able to modify the object itself, and I don't want to.

I used the simple method as before, but returned the result as a string ... but sometimes it hurts when you have a complex statement that depends on different tables.

+1


a source to share


1 answer


The problem you are facing (complex statements depending on different tables) is an old and widespread problem within ORMs in general. There are many things SQL can do that the ORM does not perform well. Inevitably, you have to differentiate in complexity by writing a lot of complex code in your controller or your view.

Instead, use the Domain Model pattern and encapsulate complex database logic with multiple tables in one place so your controllers and views won't be called "I need to know all the details. They just know about the interface of your domain model class and this class is fully responsible for how to get information from the database.



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

+5


a source







All Articles