<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Automate Db Model Creation with Zend_CodeGenerator_Php_Class</title>
	<atom:link href="http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/</link>
	<description>Blogging about PHP, Actionscript, MySQL, and other interests.</description>
	<lastBuildDate>Sat, 04 Feb 2012 04:50:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Joey</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-1824</link>
		<dc:creator>Joey</dc:creator>
		<pubDate>Wed, 31 Aug 2011 03:14:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-1824</guid>
		<description>Hey Xuhaib, for this example I was using the Zend Framework so if you aren&#039;t currently using it this example would be confusing. You don&#039;t have to use the framework though, if you only use the code generator class by including it into your project and some db connection you should still be able to create a similar working project as this one. I unfortunately don&#039;t have an example handy to show.</description>
		<content:encoded><![CDATA[<p>Hey Xuhaib, for this example I was using the Zend Framework so if you aren&#8217;t currently using it this example would be confusing. You don&#8217;t have to use the framework though, if you only use the code generator class by including it into your project and some db connection you should still be able to create a similar working project as this one. I unfortunately don&#8217;t have an example handy to show.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xuhaib</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-1821</link>
		<dc:creator>Xuhaib</dc:creator>
		<pubDate>Sun, 28 Aug 2011 05:25:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-1821</guid>
		<description>Hi

I am kinda new to Zend. And this seriously is some smart work done by you here. I didn&#039;t know about CodeGen before so thanks on that part too.

However, I am a little confused as to how is this code executed to generate the requisite php files.

Hope you are still reachable through this link.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>I am kinda new to Zend. And this seriously is some smart work done by you here. I didn&#8217;t know about CodeGen before so thanks on that part too.</p>
<p>However, I am a little confused as to how is this code executed to generate the requisite php files.</p>
<p>Hope you are still reachable through this link.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Automatiser la création de modèles avec Zend_CodeGenerator_Php_Class &#124; Simple Entrepreneur</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-467</link>
		<dc:creator>Automatiser la création de modèles avec Zend_CodeGenerator_Php_Class &#124; Simple Entrepreneur</dc:creator>
		<pubDate>Thu, 11 Mar 2010 06:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-467</guid>
		<description>[...] Lire l&#8217;article original [...]</description>
		<content:encoded><![CDATA[<p>[...] Lire l&#8217;article original [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joey</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-214</link>
		<dc:creator>Joey</dc:creator>
		<pubDate>Thu, 04 Feb 2010 14:43:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-214</guid>
		<description>Leonard,

I understand your question now, thanks for clearing that up. To best honest, I haven&#039;t taken this code past where it is now. I see this more as a starting point for a project - or a way of quickly recreating files when database tables change. For me, there seems to be little benefits in spending time adding more functionality when there are so many scenarios to be handled.

I don&#039;t believe describeTable gives you any foreign key information to know if there is a relationship in the table. I guess you would have to start by looking at the &#039;table_constraints&#039; table in &#039;information_schema&#039; to see what relationships exists for you schema (assuming we are talking about MySQL). From there, using the table_name and constraint_type fields, you would be able to know what objects need relationships to each other and where. Hope this helps.

*Edit: Actually the `information_schema`.`COLUMNS` table has probably everything you need. Shows the table, field, what table and fields are being referenced.</description>
		<content:encoded><![CDATA[<p>Leonard,</p>
<p>I understand your question now, thanks for clearing that up. To best honest, I haven&#8217;t taken this code past where it is now. I see this more as a starting point for a project &#8211; or a way of quickly recreating files when database tables change. For me, there seems to be little benefits in spending time adding more functionality when there are so many scenarios to be handled.</p>
<p>I don&#8217;t believe describeTable gives you any foreign key information to know if there is a relationship in the table. I guess you would have to start by looking at the &#8216;table_constraints&#8217; table in &#8216;information_schema&#8217; to see what relationships exists for you schema (assuming we are talking about MySQL). From there, using the table_name and constraint_type fields, you would be able to know what objects need relationships to each other and where. Hope this helps.</p>
<p>*Edit: Actually the `information_schema`.`COLUMNS` table has probably everything you need. Shows the table, field, what table and fields are being referenced.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonard Dronkers</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-213</link>
		<dc:creator>Leonard Dronkers</dc:creator>
		<pubDate>Thu, 04 Feb 2010 07:50:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-213</guid>
		<description>Hi Joey,

What I am looking for is a good way to translate  the database relations into the model representation in php. 

Lets use a simple blog entry example.

class Blog_Model_Entry{
protected $_id;
protected $_title;
protected $_content;
// @var Blog_Model_Category
protected $_category;
// @var array of Blog_Model_Tag
protected $_tags;
//...
}

Aboveyou can see the relation with parent table Category.

What I am currently doing is: (In the mapper class of the blog entry) I instantiate the category mapper to map the parent row to a category model class. An example:

// from the blog entry mapper class
public function map(Zend_Db_Table_Row $row, Blog_Model_Entry $model)
{
$model-&gt;setId($row-&gt;id);
$model-&gt;setTitle($row-&gt;title);
$model-&gt;setContent($row-&gt;content);

// find parent row, possible with defined table relation
$cat = $row-&gt;findParentRow(&#039;Blog_Model_DbTable_Category&#039;);

// instantiate category, mapper and then map
$category = new Blog_Model_Category();
$mapper = new Blog_Model_CategoryMapper();
$mapper-&gt;map($cat, $category);

// set Blog_Entry_Model category 
$model-&gt;setCategory($category);

// something similar for tags and comments
//...
//...
} 

So to go back to my question; for generating code, how would you look at this or have you found a good solution to generate code in this way (for scenarios where you have 1:1, 1:n, n:m relations)</description>
		<content:encoded><![CDATA[<p>Hi Joey,</p>
<p>What I am looking for is a good way to translate  the database relations into the model representation in php. </p>
<p>Lets use a simple blog entry example.</p>
<p>class Blog_Model_Entry{<br />
protected $_id;<br />
protected $_title;<br />
protected $_content;<br />
// @var Blog_Model_Category<br />
protected $_category;<br />
// @var array of Blog_Model_Tag<br />
protected $_tags;<br />
//&#8230;<br />
}</p>
<p>Aboveyou can see the relation with parent table Category.</p>
<p>What I am currently doing is: (In the mapper class of the blog entry) I instantiate the category mapper to map the parent row to a category model class. An example:</p>
<p>// from the blog entry mapper class<br />
public function map(Zend_Db_Table_Row $row, Blog_Model_Entry $model)<br />
{<br />
$model-&gt;setId($row-&gt;id);<br />
$model-&gt;setTitle($row-&gt;title);<br />
$model-&gt;setContent($row-&gt;content);</p>
<p>// find parent row, possible with defined table relation<br />
$cat = $row-&gt;findParentRow(&#8216;Blog_Model_DbTable_Category&#8217;);</p>
<p>// instantiate category, mapper and then map<br />
$category = new Blog_Model_Category();<br />
$mapper = new Blog_Model_CategoryMapper();<br />
$mapper-&gt;map($cat, $category);</p>
<p>// set Blog_Entry_Model category<br />
$model-&gt;setCategory($category);</p>
<p>// something similar for tags and comments<br />
//&#8230;<br />
//&#8230;<br />
} </p>
<p>So to go back to my question; for generating code, how would you look at this or have you found a good solution to generate code in this way (for scenarios where you have 1:1, 1:n, n:m relations)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joey</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-204</link>
		<dc:creator>Joey</dc:creator>
		<pubDate>Wed, 03 Feb 2010 13:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-204</guid>
		<description>Hey Leonard, I do it like so:
&lt;a href=&quot;http://martinfowler.com/eaaCatalog/dataMapper.html&quot; rel=&quot;nofollow&quot;&gt;http://martinfowler.com/eaaCatalog/dataMapper.html&lt;/a&gt;

I call the mapper directly to do basic &lt;a href=&quot;http://en.wikipedia.org/wiki/Create,_read,_update_and_delete&quot; rel=&quot;nofollow&quot;&gt;CRUD&lt;/a&gt; operations which uses the DbTable. In the case of fetch/fetchAll on the mapper, the mapper returns an instance or an array of object instances specific to that mapper.

So, if we are talking about Users, I&#039;ll have a UserModel, UserMapper, UserDbTable (I like to store each in a different folder). If I want to grab all users I would do something like:

$mapper = new UserMapper();
$users = $mapper-&gt;fetchAll();

The fetchAll method in the mapper would call the UserDbTable instance fetchAll. For example:

$table = new UserDbTable();
return $table-&gt;fetchAll();
</description>
		<content:encoded><![CDATA[<p>Hey Leonard, I do it like so:<br />
<a href="http://martinfowler.com/eaaCatalog/dataMapper.html" rel="nofollow">http://martinfowler.com/eaaCatalog/dataMapper.html</a></p>
<p>I call the mapper directly to do basic <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete" rel="nofollow">CRUD</a> operations which uses the DbTable. In the case of fetch/fetchAll on the mapper, the mapper returns an instance or an array of object instances specific to that mapper.</p>
<p>So, if we are talking about Users, I&#8217;ll have a UserModel, UserMapper, UserDbTable (I like to store each in a different folder). If I want to grab all users I would do something like:</p>
<p>$mapper = new UserMapper();<br />
$users = $mapper->fetchAll();</p>
<p>The fetchAll method in the mapper would call the UserDbTable instance fetchAll. For example:</p>
<p>$table = new UserDbTable();<br />
return $table->fetchAll();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonard Dronkers</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-203</link>
		<dc:creator>Leonard Dronkers</dc:creator>
		<pubDate>Wed, 03 Feb 2010 11:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-203</guid>
		<description>Hi Joey,

Have you maybe already worked out how the DbTable, Model and Mapper work with table relations? I am working on something similar but I haven&#039;t yet found a good way to deal with table relationships. 

What I have for now is up for download. I didn&#039;t use the code generator classes from zend though. (http://www.sreknord.net/download#download3)</description>
		<content:encoded><![CDATA[<p>Hi Joey,</p>
<p>Have you maybe already worked out how the DbTable, Model and Mapper work with table relations? I am working on something similar but I haven&#8217;t yet found a good way to deal with table relationships. </p>
<p>What I have for now is up for download. I didn&#8217;t use the code generator classes from zend though. (<a href="http://www.sreknord.net/download#download3" rel="nofollow">http://www.sreknord.net/download#download3</a>)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRL</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-129</link>
		<dc:creator>RRL</dc:creator>
		<pubDate>Wed, 06 Jan 2010 11:48:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-129</guid>
		<description>I&#039;ll strart applying it to my new application. Will test it against Flex VOs :D</description>
		<content:encoded><![CDATA[<p>I&#8217;ll strart applying it to my new application. Will test it against Flex VOs <img src='http://www.joeyrivera.com/blog_new/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zend Framework Blog &#187; Blog Archive &#187; Aus den Zend Framework Blogs</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-128</link>
		<dc:creator>Zend Framework Blog &#187; Blog Archive &#187; Aus den Zend Framework Blogs</dc:creator>
		<pubDate>Thu, 31 Dec 2009 22:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-128</guid>
		<description>[...] Rivera schreibt über die automatische Erstellung von Models mit Zend_CodeGenerator_Php_Class. Sehr [...]</description>
		<content:encoded><![CDATA[<p>[...] Rivera schreibt über die automatische Erstellung von Models mit Zend_CodeGenerator_Php_Class. Sehr [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Automate Db Model Creation with Zend_CodeGenerator_Php_Class &#171; HackIX</title>
		<link>http://www.joeyrivera.com/2009/automate-model-creation-with-zend_codegenerator_php_class/comment-page-1/#comment-127</link>
		<dc:creator>Automate Db Model Creation with Zend_CodeGenerator_Php_Class &#171; HackIX</dc:creator>
		<pubDate>Wed, 30 Dec 2009 21:26:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.joeyrivera.com/?p=462#comment-127</guid>
		<description>[...] checking out; Joey&#8217;s Blog   Tags: Models, Zend Framework, Zend_CodeGenerator    Share this [...]</description>
		<content:encoded><![CDATA[<p>[...] checking out; Joey&#8217;s Blog   Tags: Models, Zend Framework, Zend_CodeGenerator    Share this [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

