Is there a CFWheels way to keep ORM calls in the controller when looping over each record in a query? #1359
|
I'd like to find out if CFWheels has a way to keep the calls to data objects in the CFWheels ORM in the controller when looping over each record and based on a key in that record, requesting details about that item for display inside the loop? The apparent answer is that you can't avoid this, but I want to make sure there isn't some under-the-hood way of achieving the same thing but from in the controller. Notice here that as each getProjectLogsInfo record is looped over, additional details is obtained about that record based on it's key. Let me know if there is a way to move this out of the View. |
Replies: 1 comment
|
Well... that logic doesn't belong in the controller any more than it belongs in the view. Looping over one set of DB data to then get another set of DB data is a bit of an anti-pattern as well. See https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping as a starting place for reading up on that. At a minimum, push the loop and the four highlighted lines back into the model where they belong. Probably in If you wanted to stick with the ORM methods (I wouldn't), you could poss put a CFWheels model atop of a DB view that does the underlying SQL such that you can call It's unclear what |

Well... that logic doesn't belong in the controller any more than it belongs in the view.
Looping over one set of DB data to then get another set of DB data is a bit of an anti-pattern as well. See https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping as a starting place for reading up on that.
At a minimum, push the loop and the four highlighted lines back into the model where they belong. Probably in
ProjectLogsclass by the looks. Try to write one query that encompasses all the data fetched by the original call that returns the data ingetProjectLogsInfo(not a good variable name for a recordset btw: lose theget(it makes it sound li…