3
votes

getting this error;

[Emergency] Uncaught InvalidArgumentException: has_many relation abc\def\ghi\Customer.OrderRegistrants references class Order which doesn't exist

 private static $has_many = [
        'OrderRegistrants'      => 'Order.Registrant'
]
1
does the class Order exist? Does Order have a $has_one referencing this class? - Isaac
@Isaac yes order class is there, private static $has_one = [ 'Registrant' => Customer::class, ] - kosala manojeewa
What about the namespace of the Order class? - Isaac
@Isaac nothing wrong with namespace, with has_one I can use private static $has_one = [ 'Order' => Order::class, ]; even with has_many I can use private static $has_many = [ 'Orders' => Order::class, ]; but cant use "ClassName.Field" , - kosala manojeewa
@Isaac I got the solution, Robbie Averill made it, thank you all - kosala manojeewa

1 Answers

1
votes

Assuming Order has a namespace, you're not referencing it correctly. Try this:

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

This will ensure that any imported (via use My\Package\Order; for example) namespaces for the Order class will be honoured. The way you've got it won't take any namespaces into account.