Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to user multiple times relation? #648

Closed
cierzniak opened this issue Nov 30, 2016 · 6 comments
Closed

How to user multiple times relation? #648

cierzniak opened this issue Nov 30, 2016 · 6 comments
Milestone

Comments

@cierzniak
Copy link

I have system to organize events and for testing purposes i need to make fixtures with few inheritances of one entity. How to make it possible to eg. get one enttiy and use it multiple times in second?

AppBundle\Entity\Venue:
  venue_{0..9}:
    name (unique): '<text(30)>'
    address: '<address()>'
    description: '<sentence()>'
    maxSpace: '<numberBetween(400, 600)>'
AppBundle\Entity\Event:
  event_{0..499}:
    name (unique): '<text(80)>'
    description: '<sentence()>'
    image: '<imgName()>'
    totalTickets: '<numberBetween(150, @venue*->maxSpace)>'
    created: '<dateTimeBetween("-150 days", "now")>'
    dateOfEvent: '<dateTimeBetween($created, "+200 days")>'
    author: '@user*'
    venue: '@venue*'

When I check it by SQL:

SELECT a.*, b.*
FROM event a
JOIN venue b ON b.id = a.venue_id
WHERE b.max_space < a.total_tickets

I have eg. 40 records shown (so max tickets is more than max space in venue).

@cierzniak
Copy link
Author

Or how to chec condition? If @user->isActive() assign him to this fixture

@theofidry
Copy link
Member

theofidry commented Dec 1, 2016

I think you can do it by using variable references:

AppBundle\Entity\Venue:
  venue_{0..9}:
    name (unique): '<text(30)>'
    address: '<address()>'
    description: '<sentence()>'
    maxSpace: '<numberBetween(400, 600)>'

AppBundle\Entity\Event:
  event_{0..499}:
    venue: '@venue*'
    # ...
    totalTickets: '<numberBetween(150, $venue->maxSpace)>'

This should work, but I may not have accounted for that in the Expression Language... But if it doesn't, it something that should be added

@cierzniak
Copy link
Author

    venue: '@venue*'
    ...
    totalTickets: '<numberBetween(150, $venue->maxSpace)>'

Gives error Cannot access private property AppBundle\Entity\Venue::$maxSpace

    venue: '@venue*'
    ...
    totalTickets: '<numberBetween(150, $venue*->maxSpace)>'

Gives error Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR)

So still nothing :(

@theofidry
Copy link
Member

Should be $venue not $venue*, $venue is to refer to the value affected for the venue property (note that it's different from @self->venue for example.

I'm not sure I want to give support for this thing with the current Expression Language, maybe this would be more easily doable with #601.

Meanwhile, an easy although less elegant way is to use a faker provider:

class EventProvider
{
    public function maxSpace(Venue $venue)
    {
        return $venue->getMaxSpace();
    }
}

Just thought about this, maybe the following would work:

totalTickets: '<numberBetween(150, <($venue->maxSpace)>)>'

@theofidry theofidry added the Bug label Jan 30, 2017
@theofidry theofidry added this to the 3.0.0 milestone Jan 30, 2017
@theofidry
Copy link
Member

@cierzniak sorry to come back a bit late on it, I think #648 (comment) should work on it, the error you get:

Cannot access private property AppBundle\Entity\Venue::$maxSpace

Seems to indicate there is no getter for that value

@theofidry
Copy link
Member

Stupid of me: I assumed it was in 3.x but it works fine there, it's a problem of 2.x which doesn't support the $vanue*->maxSpace. It may be possible to fix it, but that's what 3.x is for really :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants