Page 1 of 1

Using an ORM solution like Propel

Posted: Fri Mar 30, 2007 10:53 am
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.

Posted: Fri Mar 30, 2007 10:57 am
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.

Posted: Fri Mar 30, 2007 11:08 am
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

Posted: Tue Apr 03, 2007 8:02 am
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 :)