drnf593779
2014-05-19 13:48
浏览 34
已采纳

Silverstripe 3.1 - 无法创建新的many_many关系

while extending the CsvBulkUploader to fit my needs, I cam across the problem, that Silverstripe doesn't let me create a new entry for a many_many relation.

My dataobject is ShopItems and has a many_many relation called Visuals. So in my MySQL database I get ShopItems_Visuals.

Now I want to create a new entry for this with the following code, and I think here's the place I made some mistake.

...    
    $visual = ShopItem_Visuals::create();
    $visual->ImageID = $file->ID;
    $visual->ShopItemID = $obj->ID;
    $visual->write();
...

after adding this to my function, I receive Class 'ShopItem_Visuals' not found after hitting the import button.

Is that because the database Table was created through the many_many relation in ShopItem and has no ClassName itself?

Can someone tell me how to create a new entry for this relation?

Thank you in advance.

图片转代码服务由CSDN问答提供 功能建议

在扩展CsvBulkUploader以满足我的需求时,我突然解决了问题,Silverstripe不允许我创建一个 many_many关系的新条目。

我的数据对象是 ShopItems ,并且有一个名为 Visuals 的many_many关系。 所以在我的MySQL数据库中,我得到 ShopItems_Visuals

现在我想用以下代码为此创建一个新条目,我想这是我做的地方 有些错误。

  ... 
 $ visual = ShopItem_Visuals :: create(); 
 $ visual-> ImageID = $ file-> ID; 
  $ visual-> ShopItemID = $ obj-> ID; 
 $ visual-> write(); 
 ... 
   
 
 

添加此项后 在我的函数中,我在点击导入按钮后收到 Class'ShopItem_Visuals'not found

这是因为数据库表是通过ShopItem中的many_many关系创建的 并且没有ClassName本身?

有人可以告诉我如何为这种关系创建一个新条目吗?

提前谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题