CodeIgniter Forums
Models stepping on each other? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Models stepping on each other? (/showthread.php?tid=28384)



Models stepping on each other? - El Forum - 03-09-2010

[eluser]Unknown[/eluser]
I've got a question about models that are loaded in by the same controller.

I have an e-commerce application with multiple stores. Say Customer A is purchasing from one store that loads in a customer model. If Customer B is on the site and loads up another request that uses the customer model, will Customer B potentially use the same customer model that Customer A pulled up? The different stores have different implementations of some customer data, so I want to make sure Store X's customer data is not intermingled with Store Y's customer data.

How can I best ensure that Customer B doesn't use Customer A's customer model that is currently in memory in cases of high-traffic?

Should I use a factory pattern since CI has Singleton implementations of models and controllers (please shed some light and correct me if I am wrong?) I have not used a factory pattern, before by the way.

Thanks in advance.


Models stepping on each other? - El Forum - 03-10-2010

[eluser]danmontgomery[/eluser]
What you're describing is not in any way possible.


Models stepping on each other? - El Forum - 03-10-2010

[eluser]tomdelonge[/eluser]
That's not quite what singleton is. In any case, each model is instantiated as a separate object. In every request, everything is new. The models treat everything with customer a and customer b the same. If they need something treated differently, then you have to use sessions or something to store the extra data. What you're suggesting, like noctrum said, is not really a problem.