PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Feb 23, 2020 1:05 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Homemade ORM HowTo's
PostPosted: Sun Aug 19, 2012 4:41 am 
Offline
Forum Commoner
User avatar

Joined: Fri Aug 06, 2010 9:01 pm
Posts: 96
Location: Osijek, Croatia
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!


Top
 Profile  
 
 Post subject: Re: Homemade ORM HowTo's
PostPosted: Sun Aug 19, 2012 12:09 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Yes, you can certainly do a JOIN. However it may complicate your code instead of keeping the loading of the second table(s) modular. Define you interface and implement it simply -- then refactor later for performance as necessary.

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: Homemade ORM HowTo's
PostPosted: Mon Aug 20, 2012 11:14 am 
Offline
Forum Commoner
User avatar

Joined: Fri Aug 06, 2010 9:01 pm
Posts: 96
Location: Osijek, Croatia


Top
 Profile  
 
 Post subject: Re: Homemade ORM HowTo's
PostPosted: Mon Aug 20, 2012 9:35 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
If you force every field to have the table specified the adding the JOINs should be fairly simple. You may have problems with name clashes and will need to come up with some aliasing scheme for the field names in the joined tables (and then de-alias when creating dependent objects).

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group