1

我有两个结构如下所述的表:

 CREATE TABLE `up_offer` (
  `up_offer_id` int(11) NOT NULL AUTO_INCREMENT,
  `from_subscription_id` int(11) NOT NULL,
  `to_subscription_id` int(11) NOT NULL,
  PRIMARY KEY (`up_offer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `subscription` (
  `subscription_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(1000) NOT NULL,
  `code` varchar(45) NOT NULL,
  `price` decimal(6,2) NOT NULL,
  `billing_cycle` int(11) NOT NULL,
  `desc` varchar(2000) DEFAULT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `emaillist_id` int(11) NOT NULL,
  `old_created_date` datetime NOT NULL,
  `old_last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_on` datetime NOT NULL,
  `last_updated_on` datetime NOT NULL,
  `is_active` bit(1) NOT NULL DEFAULT b'1',
  PRIMARY KEY (`subscription_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

用于这两个表的 dbTable 类如下:

class Admin_Model_DbTable_Subscription extends Zend_Db_Table_Abstract
{
    protected $_name = 'subscription';
    protected $_primary = 'subscription_id';

    protected $_dependentTables = 'Admin_Model_DbTable_UpOffer';

    protected $_referenceMap = array(
        'UpOffer' => array(
            'columns'       => array('subscription_id'),
            'refTableClass' => 'Admin_Model_DbTable_UpOffer',
            'refColumns'    => array('from_subscription_id','to_subscription_id'),
        ),
    );

}

class Admin_Model_DbTable_UpOffer extends Zend_Db_Table_Abstract{
    protected $_name = 'up_offer';

    protected $_dependentTables = 'Admin_Model_DbTable_Offer'; 

    protected $_referenceMap = array(
        'Offer'=>array(
            'columns'           => 'up_offer_id',
            'refTableClass'     => 'Admin_Model_DbTable_Offer',
            'refColumns'        => 'up_offer_id'
        )
    );
}

我想从“Zend_Db_Table_Row 对象”中获取相关数据:正在编写的代码是:

$upOfferData->toArray()给出字段:

Array
(
    [up_offer_id] => 1
    [from_subscription_id] => 10
    [to_subscription_id] => 9
)

$upOfferData->findDependentRowset('Admin_Model_DbTable_Subscription');给出如下输出:

Array
(
    [0] => Array
        (
            [subscription_id] => 10
            [name] => 001
            [code] => 010
            [price] => 10.00
            [billing_cycle] => 1
            [desc] => Test
            [start_date] => 2012-04-21
            [end_date] => 2012-05-20
            [emaillist_id] => 0
            [old_created_date] => 0000-00-00 00:00:00
            [old_last_updated] => 2012-04-20 15:29:57
            [created_on] => 2012-04-20 09:59:56
            [last_updated_on] => 2012-04-20 01:31:44
            [is_active] => 1
        )

)

to_subscription_id 呢?我如何正确映射 DbTable 类以及获得所需输出的正确方法是什么?期望的应该是这样的:

Array
    (
        [0] => Array
            (
                [subscription_id] => 10
                [name] => 001
                [code] => 010
                [price] => 10.00
                [billing_cycle] => 1
                [desc] => Test
                [start_date] => 2012-04-21
                [end_date] => 2012-05-20
                [emaillist_id] => 0
                [old_created_date] => 0000-00-00 00:00:00
                [old_last_updated] => 2012-04-20 15:29:57
                [created_on] => 2012-04-20 09:59:56
                [last_updated_on] => 2012-04-20 01:31:44
                [is_active] => 1
            )
        [1] => Array
            (
                [subscription_id] => 9
                [name] => 002
                [code] => 011
                [price] => 50.00
                [billing_cycle] => 2
                [desc] => Test
                [start_date] => 2012-04-21
                [end_date] => 2012-05-20
                [emaillist_id] => 0
                [old_created_date] => 0000-00-00 00:00:00
                [old_last_updated] => 2012-04-20 15:29:57
                [created_on] => 2012-04-20 09:59:56
                [last_updated_on] => 2012-04-20 01:31:44
                [is_active] => 1
            )
    )
4

0 回答 0