duanqianpu6499 2012-02-06 22:20
浏览 24
已采纳

从Zend框架中的行集(不是单行)中检索相关行集

I'm wondering if I can use the Zend framework to retrieve additional dependent rows efficiently without resorting to a lot of custom code. I'll use the Zend example of the Bugs database to translate to my problem:

$accountsTable = new Accounts();
$accountsRowset = $accountsTable->find(1234);
$user1234 = $accountsRowset->current();       
$bugsReportedByUser = $user1234->findDependentRowset('Bugs');

However, in my case the Bugs Table would have additional dependents, which in this example could be BugReproduction. How would one retrieve these Reproductions (which have a many-to-1-Bugs). It seems like very poor coding to foreach over the $bugsReportedByUser and fetch additional dependentRowsets to get the Reproductions. This would result in 'n'-order queries, while one always wants a fixed number of queries per request.

This seems trivial with Joins, but I've not found a reasonable way to do so in the Zend ecosphere.

  • 写回答

1条回答 默认 最新

  • douza1373 2012-02-10 00:49
    关注

    Well I've thought long and hard, but it boils down to the fundamental missing of the rowset-method->getDependentRowset. (Not to be mistaken with a Row (singular)->getDepedentRowset() )

    So extending Zend_Db_Table_Row_Abtract, and use it in the example's Bugs Table class by:

    class BugsTable extends Zend_Db_Table_Abstract
    {
        protected $_name = 'bugs';
        protected $_rowsetClass = 'MyRowset';
    ...
    

    And have findDependentRowset($dependentTable) implemented in MyRowSet. A highlevel implementation would be:

    1. retrieve bugs primary keys as $ids (array).
    2. call bugsTable->find($ids) (relation could be found by using Zend_Db_Table_Relationship)
    3. You now have all dependent rows from a multiple of row*s*
    4. optional: ReproductionMapper logic would map them to objects. BugsMapper logic can then add them to the highlevel Bugs Model (not the BugsTable )
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂