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

SQLFilters enahancements #1054

Closed
wants to merge 3 commits into from
Closed

SQLFilters enahancements #1054

wants to merge 3 commits into from

Conversation

v3labs
Copy link

@v3labs v3labs commented Jun 10, 2014

SQL filters in Doctrine are a bit too limited for my taste.
This pull request makes the current connection available inside sql filter classes.
The connection is needed to quote identifiers or values and generate sql statements for the current database. (sample use-case https://github.com/Atlantic18/DoctrineExtensions/blob/master/lib/Gedmo/SoftDeleteable/Filter/SoftDeleteableFilter.php)
Currently you can access the connection only through reflection which let's face it - is a hack.

I've also made the class depend on EntityManagerInterface instead of EntityManager.

There's a test for the new method.

Make connection available in filters
Add test for the changes
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3161

We use Jira to track the state of pull requests and the versions they got
included in.

*/
final public function __construct(EntityManager $em)
final public function __construct(EntityManagerInterface $em)
Copy link
Member

Choose a reason for hiding this comment

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

changing the typehint is a BC break

@v3labs
Copy link
Author

v3labs commented Jun 10, 2014

Why? This is a final method?
I'll revert the change - I was just wondering what the BC break in this case might be.

@v3labs
Copy link
Author

v3labs commented Jun 10, 2014

Reverted

@stof
Copy link
Member

stof commented Jun 10, 2014

hmm, indeed, for a final method, it is not a BC break as the typehint gets more generic. But this should be done separately anyway.

@stof
Copy link
Member

stof commented Jun 10, 2014

@v3labs why not using the filter parameters to quote them ? they get quoted by the SQLFilter class

@v3labs
Copy link
Author

v3labs commented Jun 10, 2014

It's not only quoting. It's more about sql expressions that get generated by methods like:
->getIsNullExpression
->getIsNotNullExpression
etc.

You need the database platform class which cannot be accessed without access to the connection.

I guess only a subset of these methods can be proxied in the SQLFilter class but it seems kind of pointless.

@v3labs
Copy link
Author

v3labs commented Jun 24, 2014

Any feedback?

@Ocramius
Copy link
Member

Seems sane to me. Ping @asm89

$reflMethod = new \ReflectionMethod('Doctrine\ORM\Query\Filter\SQLFilter', 'getConnection');
$reflMethod->setAccessible(true);

$this->assertTrue($reflMethod->invoke($filter) === $conn);
Copy link
Member

Choose a reason for hiding this comment

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

I think this should rather be $this->assertSame($conn, $reflMethod->invoke($filter));

@deeky666
Copy link
Member

deeky666 commented Aug 8, 2014

Besides the assertion optimization this looks reasonable to me. Ping @asm89

@v3labs
Copy link
Author

v3labs commented Aug 8, 2014

I just fixed the assertion issue.

@Ocramius
Copy link
Member

@v3labs rebased, merged, thanks!

master: ef113e5

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

Successfully merging this pull request may close these issues.

5 participants