Magento:添加订单模型和自定义模块模型之间的关系,并具有数据库约束
我创建了一个具有自己的表faces
的模块。此外,模块设置添加了一个 face_id
属性 sales/order 来连接它们:
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$this->getTable('faces')}` (
`face_id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`face_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
");
if (Mage::helper('faces')->isSalesFlat()) { // 1.4
// TBD
} else { // 1.3
$eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
$eav->addAttribute('order', 'face_id', array('type' => 'int'));
}
$installer->endSetup();
这在我的 1.3.2.4 安装中效果很好。但我想要了解 order
和 face
之间关系的某些方面。也就是说,我希望能够做这样的事情:
$face = $order->getFace(); // This method doesn't exist right now
$faceTitle = $face->getTitle();
另外,我想添加约束。我会将它们直接添加到 CREATE TABLE SQL,但我想知道如果我使用某种内置方法来创建这种关系,它们是否会自动添加。
I've created a module that has its own table faces
. Also, the module setup adds a face_id
attribute sales/order to connect them:
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$this->getTable('faces')}` (
`face_id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`face_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
");
if (Mage::helper('faces')->isSalesFlat()) { // 1.4
// TBD
} else { // 1.3
$eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
$eav->addAttribute('order', 'face_id', array('type' => 'int'));
}
$installer->endSetup();
This is working great in my 1.3.2.4 install. But there are aspects of the relationship between order
and face
that I'd like to have. Namely, I'd like to be able to do things like this:
$face = $order->getFace(); // This method doesn't exist right now
$faceTitle = $face->getTitle();
Also, I'd like to add constraints. I would add them directly to the CREATE TABLE
SQL, but I'm wondering if they are automatically added if I use some sort of built in method for creating this relationship.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,它们不会自动添加。您可以选择将此信息存储在订单表中(通过在设置期间直接修改它以添加该列),或者您可以创建一个表来连接这两个表(基本上是
order_face
)。前者的好处是,它可以让你将数据拉入订单中,并且至少自动获取 $order->getFaceId() 。通过快速更改模型,您可以自动加载该面。希望有帮助!
谢谢,
乔
No, they are not added automatically. You could choose to store this information on the order table (by modifying it directly to add that column during setup) or you could create a table to join the two (
order_face
basically). The advantage of the former is that it would allow you to pull the data into the order and at least get $order->getFaceId() automatically. With a quick change to the model you could load that face automatically.Hope that helps!
Thanks,
Joe