views:

16

answers:

1

If I have an event/function that requires changing a lot of different variables in my Active Record, should I directly access them and change them all at once from my library or have the library do multiple model calls?

The data I want to change is spread over a handful of different mysql tables but some are within the same table.

I'm concerned that doing the multiple model calls will hurt performance but doing the alternative will probably break modularity and prevent reusability.

A: 

For me, each model represents one table anyway. (I think most people do it this way) If the data needs to be changed in multiple tables, I have to make calls to multiple models.

I think it's better to use the models the way they're intended (rather than not at all). When I first used codeigniter, I didn't use them because I thought active record (or at least codeigniter's implementation of it) made it so easy to work with the database. Once I realized how models can be used I never looked back.

I also might add that this really depends on the size of the application. Maybe there's not a lot of tables and you need the highest performance; it might be completely fine to do it with calls to active record from your controller.

In the end, I think re-usability and maintainability are most important.

You might also be able to use your models to build up the queries and not execute them, and then execute them altogether (is that where you're thinking you would lose performance?)

Matthew