1

incidents、およびの 3 つのテーブルがincident_propertiesありproperty_typesます。

私がやりたいことは次のとおりです。

  1. incidents1 行のテーブルをクエリする
  2. すべてのプロパティを取得します (キーと値の行と type_id です)。
  3. property_typeプロパティごとに、テーブルからそのタイプを取得します

だから私はこのテーブル関係を設定しました -

class Incidents extends Zend_Db_Table_Abstract
{
    protected $_name = 'incidents';
    protected $_dependentTables = 'Properties';

}

class IncidentProperties extends Zend_Db_Table_Abstract
{
    protected $_name = 'incident_properties';
    protected $_dependentTables = 'PropertyTypes';
    protected $_referenceMap = array(
        'Incidents' => array(
            'refTableClass' => 'Incidents',
            'refColumns' => 'incident_id'
        )
    );
}

class PropertyTypes extends Zend_Db_Table_Abstract
{
    protected $_name = 'incident_property_types';
    protected $_referenceMap = array(
        'Properties' => array(
            'refTableClass' => 'IncidentProperties',
            'refColumns' => 'property_type_id'
        ) 
    );
}

私のincidentsモデルマッパーでは、次のようなことをしたいと思います:

$select = $this->_dbTable->select()->where('id = ?',$incident->get_id());

$incident_properties = $this->_dbTable
                            ->fetchRow($select)
                            ->findDependentRows('IncidentsProperties')
                            ->toArray();
print_r($incident_properties);

そして$incident_properties、そのタイプ行内のプロパティのキー、値、およびタイプを取得します。

これを正しい方法で達成する方法はありますか?

4

1 に答える 1

0

さて、行きましょう。

1: $_dependentTables には常に完全なクラス名を追加する必要があります。したがって、データベースからテーブル名を追加するのではなく、Zend_Db_Table_Abstract のインスタンスのクラス名を追加します。

したがって、次のようになります。

class Incidents extends Zend_Db_Table_Abstract
{
    protected $_name = 'incidents';
    protected $_dependentTables = 'IncidentProperties';

}

2: 次のように、columns 属性を referenceMap に追加する必要があります。

protected $_referenceMap = array(
    'Incidents' => array(
        'refTableClass' => 'Incidents',
        'refColumns' => 'incident_id',
        'columns' => 'name of the column that references the incident_id'
     )
);

わかりましたので、やりたいことは次のとおりです。

class IncidentMapper
{
    protected $_dbAdapter; //an instance of your Incident-Class extending Zend_Db_Table_Abstract

    public function doSomeStuff($incidentID)
    {
         $incident = $this->_dbAdapter->find($incidentID);
         //fetch dependent rowsets using incident_id
         $incidentProperties = $result->findDependentRowset('IncidentProperties', 'Incidents');
         foreach($incidentProperties as $incidentProperty)
         {
             //fetch parent row using property_type_id
             $propertyType = $incidentProperty->findParentRow('PropertyTypes', 'Properties');
         }
    }
}

そして、アダプターをデータ配列として使用する場合は、呼び出す必要があります

->toArray()

あなたの結果に。

したがって、最初に、Incidences-Class のインスタンスを次の方法で受け取ります。

->find($incidentID)

それからあなたは電話します

->findDependentRowset('ReferencedClass', 'Rule')

フェッチされたインシデントの ID を持つすべての IncidentProperties を取得します。その後、見つかったすべてのプロパティをループして呼び出します

->findParentRow('ReferencedClass', 'Rule')

PropertyType を取得します。

お役に立てば幸いです。さらに詳しい情報が必要な場合は、ReferenceGuide - Zend_Db_Tableをご覧ください。

最初は少しわかりにくく、戸惑います。他にご不明な点がございましたら、お気軽にお問い合わせください。

編集:

現時点では、プロパティをアダプターとして受け取るか、データ配列として受け取るかはよくわかりません。(そして、残念ながら私は今それをテストすることができません) したがって、問題が発生した場合は、おそらく次のようにすべての IncidentProperty を取得する必要があります。

$_incidentPropertyAdapter->find($incident_property_id)

電話をかける前に

->findParentRow(...)
于 2012-09-23T20:39:30.000 に答える