Using an ORM solution like Propel

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
InterHat
Forum Newbie
Posts: 7
Joined: Wed Feb 22, 2006 2:03 pm

Using an ORM solution like Propel

Post by InterHat »

I'm not ENTIRELY sure of what I'm doing just yet with OOP PHP, but I'm trying my best to do things the right way. Previously, I had a number of functions used in various places throughout the application. I kept them in common libraries that were accessible through the _autoload function. The details of the project are somewhat irrelevant for my question I think.

I've now moved to an ORM solution, Propel specifically. I've created used it to create classes for each of my database tables. I'm not really sure how I work with this now. When I'm adding new functionality to the system, do I add to the classes that Propel has created? For instance, I have a function to find out if there are duplicate users. It does a simple select statement and returns true or false. Does it make sense to leave this as separate function or should I add it as a function to the Propel User class?

If I were to add it to the Propel classes, each time a user was registering with my application I would create a new user with their ID and then do something like if($user->isDuplicateUser()) then { $shoutAngrily->atPeople(); } Otherwise, I'd just leave it as a function outside of the class. Does it make sense to add functions like this to the classes propel has created for me or would that be some sort of class bloat? Thanks for any and all help.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Streamline it. If there is need for the functionality in more than one location in the application, make it its own function. There is no reason why it cannot be called from another function that needs its functionality.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'll be following this thread since I'm about to delve into propel myself as part of the symfony framework. I'm taking a learn-as-you-go approach to learning symfony.

If it's any help, here's symfony's docs for using the Model layer in symfony which is powered by propel's ORM.

http://www.symfony-project.com/book/tru ... odel-Layer
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ok, I'm in a better position to answer this now. No, don't add methods directly to the classes propel creates. This will cause you issues if ever you change your schema (highly probable). What you should do is subclass the propel generated class and add your own methods there. Obvious really when you think about it :)
Post Reply