Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Multiple identifiers in In #5854

Closed
wants to merge 9 commits into from
Closed

Multiple identifiers in In #5854

wants to merge 9 commits into from

Conversation

ojhaujjwal
Copy link
Contributor

I have an SQL query like this:

SELECT * FROM data da INNER JOIN device_configuration d ON d.id = da.device_id WHERE (da.device_id, da.recorded_time) IN ( SELECT device_id, MAX(recorded_time) FROM data group BY device_id ) AND d.parent_id IS NULL;

Yes, you are right, it is not supported directly by Zend Framework 2.

With this PR, you can do something like:

$select->where->in(array('column1', 'column2'), $anotherSelect);

So, the above query can be written in Zend Framework 2 as:

$maxSelect->columns(array('device_id', new SqlExpression('MAX(recorded_time)')));
$maxSelect->group('device_id'); 
$select->where->in(array('device_id', 'recorded_time'), $maxSelect);
$select->join(
    'device_configuration',
    'device_configuration.id = data.device_id'
);
$select->where->isNull('parent_id');
$resultSet = $this->select($select); 

if ($values instanceof Select) {
if (is_array($identifier)) {
$identifiers = $identifier;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed this

@ojhaujjwal
Copy link
Contributor Author

@Ocramius I have updated the code. I do not know why the build is failing?

@samsonasik
Copy link
Contributor

see travis build here https://travis-ci.org/zendframework/zf2/jobs/19323397 , there is trailing_spaces need to be fixed. you can fix trailing space by php-cs-fixer and run :

php php-cs-fixer.phar fix /path/to/file.php --fixers=trailing_spaces

@ojhaujjwal
Copy link
Contributor Author

@samsonasik I tried that. No luck!

@samsonasik
Copy link
Contributor

you need to define what "No luck" is. what error you found ? have you follow the Readme ? https://github.com/fabpot/PHP-CS-Fixer/blob/master/README.rst#usage

@ojhaujjwal
Copy link
Contributor Author

@samsonasik I did exactly the same command as you said. And, then I committed and it displayed that no change was detected. That is NO LUCK!

@@ -23,8 +23,8 @@ class In implements PredicateInterface
/**
* Constructor
*
* @param null|string $identifier
* @param array $valueSet
* @param null|string $identifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need to change to null|string|array, and the later line needs to change to array|Select, i think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralphschindler Thanks for pointing out that!

@ralphschindler ralphschindler added this to the 2.3.0 milestone Feb 27, 2014
@ralphschindler ralphschindler self-assigned this Feb 27, 2014
@ojhaujjwal
Copy link
Contributor Author

@samsonasik It was my mistake. I only run cs-fixer in In.php and forgot to run in InTest.php
Now, I did and it worked!

@ralphschindler
Copy link
Member

After looking at this, I think I'd like to find a way to accomplish this without a "dynamic" specification. Primarily, this usage pattern would break the NotIn predicate.

@ralphschindler
Copy link
Member

Hey @ojhaujjwal, the solution you proposed looks to have a mutually exclusive condition where when the value is select, the identifier is processed as an array. I've made a different PR that will treat the identifier and values separately when processing them for the expression data, it is located here:

https://github.com/ralphschindler/zf2/tree/feature/5854-alternative

Can you tell me if this works for you?
This also takes into account the NotIn predicate as well.

ralphschindler pushed a commit that referenced this pull request Mar 7, 2014
Merge branch 'feature/5854-alternative' into develop

* feature/5854-alternative:
  Zend\Db\Sql\Predicate\In & NotIn * Changed specification so that it would work with NotIn * Modified the IN with select solution to include edge cases where the array of identifiers and select as a value are processed independent of one another.
  CS fixes
  Removed trailing spaces
  Update In.php
  CS fixes
  Update In.php
  Fixed alignment
  Removed trailing spaces
  Updated Tests of identifier array
  Now, identifier can also be array
@ralphschindler
Copy link
Member

Merged to develop.

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

Successfully merging this pull request may close these issues.

4 participants