alice
alice copied to clipboard
Got array instead of reference
Hello,
https://github.com/nelmio/alice/blob/v3.5.8/doc/advanced-guide.md#references
@user_{alice, bob} => @user_alice or @user_bob
If i:
client_type:
AppBundle\Entity\ClientType:
client_type_{1..10}:
name: '<name()>'
include:
- client_type.yaml
AppBundle\Entity\Client:
client_{1..20}:
name: '<name()>'
client_type: '@client_type_{1..10}'
I got:
Expected argument of type "AppBundle\Entity\ClientType or null", "array" given
It gives me an array with the 10 ClientType for the client_type field.
Is it normal?
Thank you
Which version are you using?
I think you are receiving a list of AppBundle\Entity\ClientType
when you request using {1..10}
operator.
You have option to do like this:
include:
- client_type.yaml
AppBundle\Entity\Client:
client_{1..20}:
name: '<name()>'
client_type: '<randomElement(@client_type_{1..10})>'
or simply like this:
include:
- client_type.yaml
AppBundle\Entity\Client:
client_{1..20}:
name: '<name()>'
client_type: '@client_type_*'
In the docs you provided it only says how to use the reference of the object you've created, in this case:
# this will create a collection of ClientType named as `client_type_` from 1 to 10
AppBundle\Entity\ClientType:
client_type_{1..10}:
name: '<name()>'
you can use its reference either:
-
@client_type_1
or@client_type_2
=> single instance -
@client_type_*
=> single instance -
@client_type_{1..10}
=> the whole collection you've created
Thank you for your help. I am using the version 3.5.8.
With @client_type_{1, 2, 3}
i should have @client_type_1 or @client_type_2 or @client_type_3 but it gives me an array with the three, sounds like a bug to me.
Actually whenever you use the operator {}
you automatically is creating a collection.
In you creation you define @client_type_{1, 2, 3}
=> then it's available to use @client_type_1
or @client_type_2
or @client_type_3
.
The operator to get a random one is @client_type_*
To solve your problem you can follow the comment above it will be fine for you.
include:
- client_type.yaml
AppBundle\Entity\Client:
client_{1..20}:
name: '<name()>'
client_type: '<randomElement(@client_type_{1..10})>'
I am using the randomElement feature, It is just to ask if the doc is wrong or not and to report it if it is the case.
Because of @user_{alice, bob} => @user_alice or @user_bob
in https://github.com/nelmio/alice/blob/v3.5.8/doc/advanced-guide.md#references
Closing here, thank you for your help.
Let's check if that's a bug or the doc that is not correct :)
To me, this is a documentation issue. It should say and
, not or
.
https://github.com/nelmio/alice/blob/v3.11.0/doc/relations-handling.md#multiple-references documents this syntax as producing an array.