CodeIgniter Forums
DataMapper solve saves deep relations in session? - 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: DataMapper solve saves deep relations in session? (/showthread.php?tid=31510)



DataMapper solve saves deep relations in session? - El Forum - 06-22-2010

[eluser]titoneo[/eluser]
Hello everyone!

This is my first post in this forum and since I started to learn Code Igniter I have to say I love it!

I was reading about the DataMapper documentation because I need a ORM for my project.

I need to create an object structure that can be saved in the session to save later in DB.

Code:
Project
|
|-Name
|-Date
|-Members (Related)
|
|-House (Related)
    |
    |-Chairs (Related)
    |-....
....


In others ORM's (like JPA in Java) you can do something like this (the syntax is not exactly like that but I think they also understood):

Code:
//Creation in first controller
house = new House();
house.addChair(new Chair('chair1'));
house.addChair(new Chair('chair2'));

project = new Project();
project.setHouse(house);


... //other stuff to set

session['project'] = project;


//Update in second controller
project = session['project'];
project.getHouse().addChair(new Chair('chair3'));
session['project'] = project;


//Saving in third controller
project = session['project'];
project.save();

DataMapper I think is pretty good, but not find a way to keep all the structure in a simple object in the session, update and save in the end with a simple call. Additionally, with DataMapper, when you have to save a one to many relation you have to think about which object references to the other in database (think of tables) and I think it is just the opposite of how objects work (think of objects), isn't it?


Thanks


DataMapper solve saves deep relations in session? - El Forum - 06-24-2010

[eluser]titoneo[/eluser]
Any suggestion? I have being seen Doctrine and does what I want.

But I can't store my models objects, that extends Doctrine_Record, in session (using Session codeigniter class) because they have a large size when serializing.

In this case, I have to create aditional 'transfer objects' to store them in session.

Another option is to use native sessions..

Any elegant solution?

Thanks