[geeklog-devel] Geeklog 2 and Propel

Tony Bibbs tony at tonybibbs.com
Fri Nov 5 15:34:50 EST 2004


Ok, just ran another test which pretty much cements it for me.  In my 
data model I have a two tables: ae_application and ae_app_privileges.  
The relationship to the two is that an ae_application record can show up 
on many ae_app_privileges records which is enforced with your typical 
foreign key constraint.

By making sure the Propel schema.xml includes all foreign key 
constraints, the model objects created by propel automagically include 
the getters for this.  So, to be clear, the AeAppPrivileges class (which 
is autogenerated by Propel) includes a getAeApplication() method on it 
which will return the corresponding AeApplication model.

More importantly, however, is that if I change the application object at 
all and then call $privilege->setAeApplication($appObj)  and turn around 
and do $privilege->save() then both tables get updated *and* it is 
neatly wrapped in a transaction.

I hope you guys find the time to give this a try.  I know Vinny has 
started which should hopefully confirm what I have been saying but this 
is definitely very useful stuff.

--Tony

Tony Bibbs wrote:

> If you do anything today please read this entire message...it's a bit 
> long but I want to be sure you all get a quick look of something that 
> really excites me and could make all our PHP5 coding faster.
>
> I just finished my test drive with Propel.  I had to do so because we 
> are looking for an Object Relational Mapping (ORM) tool to use in our 
> PHP environment here at work.  I do have it working already with a 
> copy of the Auth_Enterprise database I have.  As a recap here is what 
> it can do:
>
> 1) You can define your data model and use Propel to generate an XML 
> file that describes your database.  Here is a snippet from that file 
> (note there is a DTD you can use for validating this):
>
> <table name="ae_group">
>    <column name="grp_id" type="SMALLINT" required="true" 
> primaryKey="true"/>
>    <column name="grp_app_id" type="VARCHAR" size="30" required="true" 
> primaryKey="true" default=""/>
>    <column name="grp_logical_name" type="VARCHAR" size="50" 
> required="true" default=""/>
>    <column name="grp_display_name" type="VARCHAR" size="50" 
> required="true" default=""/>
>    <column name="grp_descr" type="VARCHAR" size="255" required="true" 
> default=""/>
>    <column name="grp_create_date" type="INTEGER" required="true" 
> default="0"/>
>    <column name="grp_change_date" type="INTEGER"/>
>    <column name="grp_change_user_name" type="VARCHAR" size="75" 
> primaryKey="true"/>
>    <foreign-key foreignTable="ae_application">
>      <reference local="grp_app_id" foreign="app_id"/>
>    </foreign-key>
>    <foreign-key foreignTable="ae_user">
>      <reference local="grp_change_user_name" foreign="user_name"/>
>    </foreign-key>
>  </table>
>
> If you look closely you'll notice it basically is the schema 
> represented in XML.  Only gotcha was that I had to define all the 
> foreign keys by hand even though this database uses foreign key.  Not 
> a huge deal.
>
> 2) Then you can build your project.  A build seems like something that 
> PHP projects shouldn't have to do but here is what happens during the 
> build:
> - Schema is used to build php5 classes, two for each table in the 
> database.  The first is the model class and it is an object the 
> represents the table with all the appropriate getters and setters.  
> The second is a 'Peer' class which is used to do searches against that 
> table
> - The config file (ini style) is then converted to a PHP array
>
> 3) You simply copy the classes and the config file over to your 
> webtree and you have at it.  Here is code to save a new application in 
> Auth_Enterprise:
>
> include_once 'propel/Propel.php';
> Propel::init('/var/www/localhost/htdocs/PropelCreoleTest/Auth_Enterprise-conf.php'); 
>
> include_once 
> 'PropelCreoleTest/classes/Auth_Enterprise/AeApplication.php';
> $app = new AeApplication();
> $app->setAppId('PROPEL_TEST_APP_ID');
> $app->setAppName('Propel Auth_Enterprise Test Application');
> $app->setAppContactEmail('tony at geeklog.net');
> $app->save(); // note this is transaction safe.
>
> Only gotcha is the build system is required on developer machines.  
> The build tool is called Phing (http://phing.info).  It seems to be 
> complicated to me yet because I don't understand how it works really 
> but using Propel most of the Phing specifics are hidden from you.  
> Note that Phing is not required when deploying applications (i.e. 
> end-users wouldn't need it).
>
> This may all seem complicated but after I got Phing, Propel and Creole 
> installed (most of which use the pear install command) I was able to 
> get this code up and running in a matter of minutes.
>
> Anyway, even if it doesn't make it into Geeklog 2 it should at least 
> be considered.  The main reason is that by using Propel, we don't 
> worry about the database access portion anymore an we can simply 
> concentrate on implementing our features.
>
> Only gotchas so far is that it requires the use of their DB 
> abstraction layer called Creole (i.e. it won't work with PEAR::DB).
>
> --Tony
> _______________________________________________
> geeklog-devel mailing list
> geeklog-devel at lists.geeklog.net
> http://lists.geeklog.net/listinfo/geeklog-devel





More information about the geeklog-devel mailing list