alice icon indicating copy to clipboard operation
alice copied to clipboard

Assign entity trough reference parameter

Open bytes-commerce opened this issue 2 years ago • 0 comments

Hello,

I have three Entities, and one requires the other. I.e. User has many Subscribers which can be part of many Segments.

With regular Alice logic, I can assign any amount of random Subscribers to Segments, but I want to get them from the User, because in each Segment there can only be Subscribers belonging to Users.

So my attempt was like so:

App\Entity\Segment:
  segment{1..25}:
    user: '@user_*'
    name: '<word()>'
    subscriber: @user_*->subscribers

But of course @user_*->subscribers is an instance of Collection, and Alice tries to use the addSubscriber method, which then logically fails.

I also tried to create a addSubscriberCollection method and use __calls function, but it seems the Segment-Logic is ran before Subscribers are even created, which of course is not ideal, because now Subscribers aren't existing.

App\Entity\Segment:
  segment_{1..25}:
    user: '@user_*'
    name: '<word()>'
    __calls:
      - addSubscriberCollection:
          collection: '@user_*->subscribers'

How could i possible chain the Fixtures in the correct order? The upper attempt seems to work, but it also seems that the provided Collection is still empty during that time. What to do?

Maybe, it would even be possible to add a parameter that will specify in which order fixtures are being loaded to be more precise here if desired.

bytes-commerce avatar Aug 07 '22 09:08 bytes-commerce