【问题标题】:silverstripe 4 has_many relationship giving errorssilverstripe 4 has_many 关系给出错误
【发布时间】:2018-07-19 04:03:29
【问题描述】:

得到这个错误;

[紧急] 未捕获的 InvalidArgumentException:has_many 关系 abc\def\ghi\Customer.OrderRegistrants 引用类 Order 哪个 不存在

 private static $has_many = [
        'OrderRegistrants'      => 'Order.Registrant'
]

【问题讨论】:

  • Order 存在吗? Order 是否有 $has_one 引用此类?
  • @Isaac 是的订单类在那里,私有静态 $has_one = [ 'Registrant' => Customer::class, ]
  • Order 类的命名空间呢?
  • @Isaac 命名空间没有问题,使用 has_one 我可以使用 private static $has_one = [ 'Order' => Order::class, ];即使使用 has_many 我也可以使用 private static $has_many = [ 'Orders' => Order::class, ];但不能使用“ClassName.Field”,
  • @Isaac 我找到了解决方案,Robbie Averill 做到了,谢谢大家

标签: php silverstripe silverstripe-4


【解决方案1】:

假设Order 有一个命名空间,您没有正确引用它。试试这个:

private static $has_many = [
    'OrderRegistrants'      => Order::class . '.Registrant',
];

这将确保Order 类的任何导入(例如通过use My\Package\Order;)命名空间都将得到尊重。您获得它的方式不会考虑任何命名空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2013-09-29
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多