ZF-2577: _dependentTables and _referenceMap should have class parameter
Description
I tried to follow Coding Standard and Naming Conventions with my database models. But it all breaks when I try $paper->findPaperWriter() or $paperWriter->findParentPaper().
CREATE TABLE paper ... CREATE TABLE paper_writer ( paper_id... );
So I'd like to have
Database/Paper.php Database/Paper/Writer.php
class Database_Paper class Database_Paper_Writer
All of this would work, if I would call $paper->findDatabasePaperWriter() or $paperWriter->findParentDatabasePaperWriter(), but as you can see this is not a very good solution. I found two solutions.
"class" parameter in _dependentTables and _referenceMap, that would tell ZF to look for certain class instead of trying magically resolve it. Zend/Db/Table/Row/Abstarct.php findDependentRowset() and findParentRow() should check for if there parameter has been set and use that instead of the one received as $dependentTable or $parentTable parameter.
have addHelperPath() similar to Zend_View View Helper
Comments
Posted by Teemu Välimäki (cred) on 2008-02-05T13:14:34.000+0000
Quick test with Zend/Db/Table/Row/Abstract.php findDependentRowset() seems to work just fine!
Posted by Teemu Välimäki (cred) on 2008-02-05T13:15:36.000+0000
Apparently I don't know how to use comment markup on here, sorry about that.
Posted by Teemu Välimäki (cred) on 2008-02-06T06:08:46.000+0000
After using my fix for a while I noticed some problems with Parent magic methods. I noticed, that there's a lot of code that would require if clauses. So instead of option 1. I presented earlier I'm now leaning towards option 2. of using addDatabasePath(). Option 2 would also be backwards compatible and would ease working.
Posted by Teemu Välimäki (cred) on 2008-02-06T13:51:47.000+0000
After some copy paste from Zend_View I have a working Zend_Db_Table_Abstract and Zend_Db_Table_Row_Abstract, that utilizes addDatabasePath() concept and this time it even seems to work without a problem.
I'll generate a patch of it tomorrow after cleanup.
Posted by Teemu Välimäki (cred) on 2008-03-17T13:31:04.000+0000
This patch modifies Db/Table/Abstract.php and Db/Table/Row/Abstract.php adding the possibility to have prefixes for database files. I have database tables on each file so hierarchially so, that it's 1:1 to the datbase.
Example of Customer table: In bootstrap Zend_Db_Table_Abstract::addRelationshipPath('../library/Site/Db/Table', 'Site_Db_Table');
../library/Site/Db/Table/Customer.php class Site_Db_Table_Customer{}
Posted by Teemu Välimäki (cred) on 2008-03-17T15:48:12.000+0000
This is a proper patch. The previous contained hardcoding from my codebase.
Perhaps the first str_replace('' could be replaced with some ZF core function?
Posted by Teemu Välimäki (cred) on 2008-03-20T06:53:29.000+0000
The _addPath had a minor defunc, when it didn't check if the path already exists.
Fixed function
Posted by Teemu Välimäki (cred) on 2008-03-20T08:20:41.000+0000
I think this is change is required to maintain compability with those who wont be using RelationshipPath. The main point is the code inside else.
Posted by Wil Sinclair (wil) on 2008-03-25T20:43:52.000+0000
Please categorize/fix as needed.
Posted by Teemu Välimäki (cred) on 2008-03-27T11:31:55.000+0000
This latest patch contains all the fixes applied against trunk.
Posted by Teemu Välimäki (cred) on 2008-03-27T11:55:28.000+0000
And of course I managed to screw newest patch up a bit. Table/Row/Abstract.php line 776 is missing closing )
Otherwise it's good to go
Posted by Teemu Välimäki (cred) on 2008-04-01T14:25:16.000+0000
My patches remove @ in front of Zend_Loader and thus, should to some extent solve the issue.
Posted by Wil Sinclair (wil) on 2008-12-04T13:17:30.000+0000
Reassigning to Ralph since he's the new maintainer of Zend_Db
Posted by Ralph Schindler (ralph) on 2009-01-10T11:09:06.000+0000
Will evaluate within 2 weeks
Posted by Ralph Schindler (ralph) on 2009-08-06T10:50:28.000+0000
Marking this as 'wont fix'. There are a couple of new components in place that would better facilitate what you are asking for. First is the module autoloader in Zend_Application. You can read about the Zend_Application_Module_Autoloader here http://framework.zend.com/docs/quickstart/… and here http://devzone.zend.com/article/4525
As for the magic finder __call() method, I would tend to stay away from it: findParentClassNameByRule() in favor of the actual calls themselves: findParentRow($class ...) and findDependentRowset($class, ...)
Have a look at the new Zend_Application functionailty, i think it solves what you are looking for.
-ralph