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

SQL Error on ManyToMany #58

Closed
jelofson opened this issue Jun 5, 2017 · 3 comments
Closed

SQL Error on ManyToMany #58

jelofson opened this issue Jun 5, 2017 · 3 comments

Comments

@jelofson
Copy link
Contributor

jelofson commented Jun 5, 2017

Using the scenario of threads, tags, and taggings, and we try the following:

$post = $atlas->fetchRecord(ThreadMapper::CLASS, 2, ['taggings', 'tags']);

If there are no associated tags for the post, then the query will fail (in mysql). Works in sqlite, so tests seem to pass.

What appears to happen is the 3rd query that is prepared will look something like this:

SELECT
    `tags`.`tag_id`,
    `tags`.`tag`
FROM
    `tags`
WHERE
    `tags`.`tag_id` IN ()

and MySQL will throw a syntax error (NOTE that sqlite does not return an error here)

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 7 in /home/jelofson/www/atlas/vendor/aura/sql/src/ExtendedPdo.php:748

Perhaps the query for tags should be issued, given that there are no taggings returned.

pmjones pushed a commit that referenced this issue Jun 5, 2017
…rds to match against, pre-emptively return an empty array instead of issuing an empty IN() query

Fixes #58.
@pmjones
Copy link
Contributor

pmjones commented Jun 5, 2017

@jelofson Check out the issue-58 branch and see if that solves this problem.

@jelofson
Copy link
Contributor Author

jelofson commented Jun 6, 2017

@pmjones On my initial test, that looks like it's fixed. Thanks!

@jelofson jelofson closed this as completed Jun 6, 2017
@pmjones
Copy link
Contributor

pmjones commented Jun 6, 2017

Sweet. Merging now.

@pmjones pmjones mentioned this issue Jun 6, 2017
pmjones pushed a commit that referenced this issue Jun 6, 2017
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

No branches or pull requests

2 participants