-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
[NFR] UPDATE query with JOIN in PHQL #146
Comments
As i wrote earlier. Did you tried it with subquieries INSTEAD of joins ? This types of PHQL queries i guess are not supported. But i think that subqueries should work so:
It should work fine. I tested it already. |
Do you mean PHQL query like this? UPDATE Version
SET Version.Price=PriceOrig
WHERE Version.TrackRef IN (SELECT TrackRef FROM RelArtistTrack WHERE RelArtistTrack.ComposerRef=:artistId:)
AND (Version.Price=0) OR (Version.Price IS NULL) I think it might be useful only for the most simple queries (update data in one table based on ids from another table). But what about joining multiple tables? UPDATE Version
LEFT JOIN RelArtistTrack ON RelArtistTrack.TrackRef=Version.TrackRef
LEFT JOIN Artist ON RelArtistTrack.ComposerRef=Artist.TrackRef
SET Version.Price=Version.PriceOrig
WHERE RelArtistTrack.ComposerRef=:artistId: AND Artist.Status=1
AND (Version.Price=0) OR (Version.Price IS NULL) Or calculating values based on the values of a few records from different tables? SET Version.Price=Version.PriceOrig * Artist.PriceModifier |
will be something like:
When you have done your relations between models then ON clause is not needed i think.
will be something like:
But it will become uglier and uglier. So the joins would be really helpful. You can rewirte joins to subqueries like in 90% of times, but it will look awful, but if you need "joins" you can use this fallback for now. @sergeyklay i think it would be really nice if phql could support joins in update statements. |
+1 |
This is still relevant. |
Still doesn't work. |
Bump |
1 similar comment
Bump |
Bump |
Still relevant |
I have some raw-sql queries, which I want translate to PHQL. For example:
raw sql:
And PHQL query of this sql query:
So, it's very simple UPDATE query with JOIN. But after executing this query I see an error:
Phalcon\Mvc\Model\Exception: Syntax error, unexpected token LEFT, near to ' JOIN RelArtistTrack ON RelArtistTrack.TrackRef=Version.TrackRef\n SET Version.Price=Version.PriceOrig\n WHERE RelArtistTrack.ComposerRef=:artistId:\n AND (Version.Price=0) OR (Version.Price IS NULL)\n ', when parsing: \n UPDATE Version\n LEFT JOIN RelArtistTrack ON RelArtistTrack.TrackRef=Version.TrackRef\n SET Version.Price=Version.PriceOrig\n WHERE RelArtistTrack.ComposerRef=:artistId:\n AND (Version.Price=0) OR (Version.Price IS NULL)\n (231)
If I understand correctly, these types of PHQL queries are not supported? Or this is a bug?
phalcon: 2.0.10
Reelated forum thread: https://forum.phalconphp.com/discussion/11065/update-query-with-join-in-phql
The text was updated successfully, but these errors were encountered: