-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add Criteria::fromFindCriteria #89
base: 2.0.x
Are you sure you want to change the base?
Conversation
f3d9832
to
b6a91c0
Compare
@@ -76,6 +76,24 @@ public static function create() | |||
} | |||
|
|||
/** | |||
* Creates an instance with same behaviour as criteria parameters passed on ORM find methods. | |||
* | |||
* @param array $findCriteria |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"array" => "Criteria[]" ? Not sure what is used in this project…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is the same as ObjectRepository::findBy
method first parameter.
I'll add a comment.
b6a91c0
to
226aeed
Compare
* Creates an instance with same behaviour as criteria parameters passed on ORM find methods. | ||
* | ||
* @param mixed[] $findCriteria Array of different keys and values. Gets the same format as argument expected on | ||
* ObjectRepository::findBy and ObjectRepository::findOneBy methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use fully qualified class names, as they are in a different package
226aeed
to
526d8bb
Compare
@stof fixed. |
Any news on this PR? |
@soullivaneuh As far as I can see in the entityPersister, if you want to make the 2 compatible you have to take into account 3 more cases and their tests.
Thanks |
@mikeSimonson Okay I'll see to update the tests first. |
526d8bb
to
78461f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also address this (after a rebase to sync with master
).
@@ -16,6 +16,18 @@ public function testCreate() : void | |||
$this->assertInstanceOf(Criteria::class, $criteria); | |||
} | |||
|
|||
public function testFromFindCriteria() | |||
{ | |||
$criteria = Criteria::fromFindCriteria(array('name' => 'test', 'foo' => 42)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use short array syntax
|
||
/** @var CompositeExpression $where */ | ||
$where = $criteria->getWhereExpression(); | ||
$this->assertInstanceOf('Doctrine\Common\Collections\Expr\CompositeExpression', $where); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ::class
syntax
78461f5
to
a4f6055
Compare
The goals is to be able to quick reproduce a criteria looking like parameters given to ORM find methods.
@mikeSimonson I updated the code to manage the first case. Stop me if I'm wrong, but I don't thing I have anything to do for the This will be simply managed by this: static::expr()->eq($key, $value); Where |
a4f6055
to
9c4e54b
Compare
Subject
The goals is to be able to quick reproduce a criteria looking like parameters given to ORM find methods.
Concrete case
On a REST controller action, I would like to setup basic filter and apply them with the
findBy
method of the ORM.I have a
Server
entity containing manyUser
entities.When the user calling the api method is not an admin, I have to filter the server list to get only related ones.
But the
findBy
does not allow us to do a search on aManyToMany
relationship.I would like to keep same method on criteria to apply it on a query builder:
Having this method would simplify the logic.