Magento:添加订单模型和自定义模块模型之间的关系,并具有数据库约束

发布于 2024-10-07 23:26:32 字数 969 浏览 3 评论 0原文

我创建了一个具有自己的表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 安装中效果很好。但我想要了解 orderface 之间关系的某些方面。也就是说,我希望能够做这样的事情:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-10-14 23:26:32

不,它们不会自动添加。您可以选择将此信息存储在订单表中(通过在设置期间直接修改它以添加该列),或者您可以创建一个表来连接这两个表(基本上是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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文