Homemade ORM HowTo's
Posted: Sun Aug 19, 2012 4:41 am
Hi everyone!
I am currently developing my own ORM out of boredom. There is a mapping file which maps database tables to my classes, and columns to class properties. For the momement, I'd like to support only basic CRUD, no custom filters, etc.; e.g. create, readByPK, update, delete, readAll. This CRUD functionality is implemented in abstract entity class which all of my entities should extend. I managed to implement this with no problem, but... I am currently stuck with foreign keys. I'd like to e.g. on readByPK if table has foreign key reference, to read referenced table and fetch object of that reference instead only it's id.
What is best way to do it? I know i can read my mapping and for each foreign key make additional query, but i am wondering is there another way? Is it possible to make it in only one query using JOIN?
Cheers!
I am currently developing my own ORM out of boredom. There is a mapping file which maps database tables to my classes, and columns to class properties. For the momement, I'd like to support only basic CRUD, no custom filters, etc.; e.g. create, readByPK, update, delete, readAll. This CRUD functionality is implemented in abstract entity class which all of my entities should extend. I managed to implement this with no problem, but... I am currently stuck with foreign keys. I'd like to e.g. on readByPK if table has foreign key reference, to read referenced table and fetch object of that reference instead only it's id.
What is best way to do it? I know i can read my mapping and for each foreign key make additional query, but i am wondering is there another way? Is it possible to make it in only one query using JOIN?
Cheers!