silverstripe / silverstripe-restfulserver

RestfulServer module for Silverstripe CMS
http://www.silverstripe.org/restfulserver-module/
BSD 3-Clause "New" or "Revised" License
45 stars 48 forks source link

DataFormatter breaks on named relations with dot notation #105

Open wernerkrauss opened 1 year ago

wernerkrauss commented 1 year ago

Given a relation like

private static $has_one = [
   'Foo' => MyClass::class . '.Bar'
];

JsonDataFormatter doesn't try to retrieve MyClass::class from Injector but the whole array value incl. .Bar...

This give an error like

{"type":"SilverStripe\\Core\\Injector\\InjectorNotFoundException","message":"ReflectionException: Class MyNamespace\\App\\DataObjects\\ProductMerge.MergeableProducts does not exist in \/home\/werner\/dev\/my-project\/vendor\/silverstripe\/framework\/src\/Core\/Injector\/InjectionCreator.php:17
...

an breaks the API.

maxime-rainville commented 1 year ago

I don't recall seeing this kind of logic before.

Is your has_one mapping to a has_many on the other object. Normally, the "dot notation" is used on the has_many, not the has_one.

Do you have an example DataObject classes for what you are trying to achieve?