Welcome Guest, Not a member yet? Register   Sign In
How to use models?
#5

[eluser]zoran119[/eluser]
[quote author="johnpeace" date="1283883461"]'application' is a bit broad...what does your model 'application' represent? Would it be better broken down into smaller pieces?[/quote]

'application' is probably ok... think of it as a membership application for a club of some kind.

yeah, i was thinking that the model should represent an entity in my application, rather than being just a 'container' for a whole heap of functions that deal with applications. in my current setup every function takes an application_id (rather than using to $this->application_id) and does whatever it needs to do in the database, which kind of makes the whole object oriented part of mvc useless.

so, in a world more similar to what you have described (model has properties that are the same as the table describing the entity) how would you deal with a query like 'update all applications submitted by bob to approved'. what's a nice way of getting all bob's applications?

i get a bit confused here... i can think of a couple of ways of doing it:

1. having another class called application_set with a private array which contains all the application instances (initialised by an sql statement for example)? and then a function set_status($new_status_id) which would iterate all the object instances and call their set_status method... this seems inefficient... too many database updates.

2. do the same as in 1, but forget the whole idea of a new application_set model/class and just do it all in the controller... but i shouldn't run sql in the controller... where do i put this function to retrieve multiple (bob's) applications?

3. just update it all the poor man's way with sql (update application set status_id = 1 where owner = 'bob')... but then this is not 'clean' and where do i put this sql anyway... doesn't belong in the controller or the application model...

not sure of what the best way would be (probably none of those). any suggestions?


Messages In This Thread
How to use models? - by El Forum - 09-07-2010, 03:33 AM
How to use models? - by El Forum - 09-07-2010, 07:17 AM
How to use models? - by El Forum - 09-07-2010, 07:51 AM
How to use models? - by El Forum - 09-07-2010, 07:52 AM
How to use models? - by El Forum - 09-07-2010, 07:59 AM
How to use models? - by El Forum - 09-07-2010, 10:34 AM
How to use models? - by El Forum - 09-07-2010, 05:15 PM
How to use models? - by El Forum - 09-07-2010, 05:16 PM
How to use models? - by El Forum - 09-07-2010, 10:55 PM
How to use models? - by El Forum - 09-08-2010, 02:46 AM
How to use models? - by El Forum - 09-08-2010, 02:55 AM
How to use models? - by El Forum - 09-08-2010, 07:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB