doumo6356 2017-05-01 14:47
浏览 19

Silverstripe DataObject Relationships - 两个has_many彼此相关

I am going a little nuts trying to figure this out, I am sure the solution is simple, but I have real trouble visualising these data relationships. So, here's what I am trying to do:

I have an object called "Offer", which needs two GridFields for "ItineraryItem" and "ItineraryTab" Data Objects

This is what I have at the minute in the three objects, but it is returning an error every time and I can't seem to figure out why.

// Offer
$has_many = array(
   "ItineraryItems" => "ItineraryItem",
   "ItineraryTabs" => "ItineraryTab"
);

// On ItineraryTab
$has_one = array(
   "Offer" => "Offer"
);
$many_many = array(
   "ItineraryItems" => "ItineraryItem"
);

// on ItineraryItem
$has_one = array(
   "Offer" => "Offer"
);
$belongs_many_many = array(
   "ItineraryTabs" => "ItineraryTab"
);

As I said, the solution is probably pretty simple, but I can't see it anymore after so many hours of trying! Please help me!

I am operating on Silverstripe 3.4, if that helps

  • 写回答

1条回答 默认 最新

  • dpjjmo3079 2017-05-02 18:20
    关注

    So, i had to answer this myself, and found something that works -- but i am not sure it is the correct way or if it's a hack. Here it is anyway, in case it helps someone.

    First off, i had to get into the database and delete the OfferID column from the Tab object.

    // Offer.php
    $has_many = array(
        'ItineraryItems' => 'ItineraryItem'
    );
    
    $many_many = array(
       'ItineraryTabs' => 'ItineraryTab', 
    );
    
    //ItineraryItem.php
    $has_one = array(
        "Offer" => 'Offer'
    );
    
    $many_many = array(
        'ItineraryTabs' => 'ItineraryTab'
    );
    
    //ItineraryTab.php
    $belongs_many_many = array(
        "ItineraryItems" => "Offer.ItineraryItems"
    );
    

    If anyone finds something more elegant, please let me know, but this seems to do the job for now.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)