Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORM and PHP class design 1

Status
Not open for further replies.

SPrelewicz

Programmer
Jul 16, 2001
124
US
I am doing an application where I have essentialy a class per table of my mySQL database. I am stuck at a one-to-many and how to implement the classes.

Specifics:
I have a property table (and class), and an apartment table(and class). The apartment table has a foreign key property_id to the property it belongs to. Currently, when I instantiate an apartment, I have a new Property being created as a property attribute. Thus, I can get the properties information by $apartment->property->get_property_name, etc...

Okay, that part seems correct. Now, if I have a property and I want to get all the apartments of that property when I instantiate the property object, I run into proplems. In the constructor I have $property->apartments = new apartmentCollector(). [I use a collector class for lists]. It hanges here, as it seems to get caught when the APARTMENT is instantiating a new Property, but I am instantiating the apartment from Property(). Makes sense?

Does anyone have any advice on how to do this properly?

Thank you,
Scott

This may not seem to PHP, but I am using PHP, and am looking for examples *in* php
 
As a follow up, since I'm asking for advice...

Should I be implementing in some way so that in the example above I could just do something like $apartment->get_property_name() without calling it from the property object. If so, how? Just have a function in apartment called get_property_name() and have it return $this->property->property_name, or is there a better way? This sint an inheritance situation, so that wouldnt work.
 
Pass the property into the apartment constructor and set it instead of creating a new property.
 
Ahh, yes Miros, that makes sense. I'll give that a go and see if my OO design falls into place.

Thank you.

Scott
 
I'm completely flummoxed by Xacte's post.
 
Sorry, posted in wrong thread...

I don't know what I was thinking [ponder]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top