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

orderBy param of find_method in ObjectSelect there's no effect #154

Closed
acaciovilela opened this Issue Jan 24, 2013 · 5 comments

Comments

Projects
None yet
4 participants
@acaciovilela

acaciovilela commented Jan 24, 2013

I have this one:

$this->add(array(
            'name' => 'accountingItemId',
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
            'options' => array(
                'empty_option' => '',
                'object_manager' => $entityManager,
                'target_class' => 'AccountingItem\Entity\AccountingItem',
                'property' => 'accountingItemName',
                'is_method' => false,
                'find_method' => array(
                    'name' => 'findAll',
                    'params' => array(
                        'orderBy' => array('accountingItemName' => 'ASC')
                    )
                )
            ),
            'attributes' => array(
                'class' => 'span4',
            )
        ));

I can set anything that there's no effect in query. Shouldn't it return an ordered list by that param?

@netiul

This comment has been minimized.

Show comment
Hide comment
@netiul

netiul Jan 25, 2013

Contributor

Not really, findAll doesn't take parameters as you can see here.

You can do the findBy with empty criteria array.

'find_method' => array(
    'name' => 'findBy',
    'params' => array(
        'criteria' => array(),
        'orderBy' => array('accountingItemName' => 'ASC'),
    ),
),

or create your own function using a custom repository.

Contributor

netiul commented Jan 25, 2013

Not really, findAll doesn't take parameters as you can see here.

You can do the findBy with empty criteria array.

'find_method' => array(
    'name' => 'findBy',
    'params' => array(
        'criteria' => array(),
        'orderBy' => array('accountingItemName' => 'ASC'),
    ),
),

or create your own function using a custom repository.

@acaciovilela

This comment has been minimized.

Show comment
Hide comment
@acaciovilela

acaciovilela Jan 25, 2013

you're right @netiul, thanks for explain!

acaciovilela commented Jan 25, 2013

you're right @netiul, thanks for explain!

@dacot11

This comment has been minimized.

Show comment
Hide comment
@dacot11

dacot11 Nov 7, 2013

I have a question kind of related to this one. I need to add a criteria for this select but the field is a collection, how can I format it. I have this:

$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'technician',
'attributes' => array(
'id' => 'technician',
'class' => 'form-control',
),
'options' => array(
'object_manager' => $objectManager,
'target_class' => '\SamUser\Entity\User',
'property' => 'first_name',
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array( 'roles' => array(1) ),
'orderBy' => array('first_name' => 'ASC'),
),
),
'empty_option' => 'Technician',
'required' => false,
),
));

I need to find users with the role technician, but in this way it is not working.

Thanks

dacot11 commented Nov 7, 2013

I have a question kind of related to this one. I need to add a criteria for this select but the field is a collection, how can I format it. I have this:

$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'name' => 'technician',
'attributes' => array(
'id' => 'technician',
'class' => 'form-control',
),
'options' => array(
'object_manager' => $objectManager,
'target_class' => '\SamUser\Entity\User',
'property' => 'first_name',
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array( 'roles' => array(1) ),
'orderBy' => array('first_name' => 'ASC'),
),
),
'empty_option' => 'Technician',
'required' => false,
),
));

I need to find users with the role technician, but in this way it is not working.

Thanks

@webdevilopers

This comment has been minimized.

Show comment
Hide comment
@webdevilopers

webdevilopers Jul 11, 2014

Good catch, @netiul ! What is the actual reason for this behaviour? Why should the findAll method not at least pass the array $orderBy = null - maybe $limit and $offset too - to the findby() method also?

BTW: I used your solution in my blog: http://blog.webdevilopers.net/how-to-use-orderby-param-on-find_method-findall-with-doctrine-objectselect/
Thanks!

webdevilopers commented Jul 11, 2014

Good catch, @netiul ! What is the actual reason for this behaviour? Why should the findAll method not at least pass the array $orderBy = null - maybe $limit and $offset too - to the findby() method also?

BTW: I used your solution in my blog: http://blog.webdevilopers.net/how-to-use-orderby-param-on-find_method-findall-with-doctrine-objectselect/
Thanks!

@netiul

This comment has been minimized.

Show comment
Hide comment
@netiul

netiul Jul 21, 2014

Contributor

No real need I guess, it's easy to accomplish the same with findBy or with your own function in a extended repo.

Contributor

netiul commented Jul 21, 2014

No real need I guess, it's easy to accomplish the same with findBy or with your own function in a extended repo.

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