-
Notifications
You must be signed in to change notification settings - Fork 369
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
Raw update queries #40
Comments
There is a simple modification that gives this possibility and works well for me. One needs to add a method like that:
I also add a factory method for instances used only to use raw update/delete/"custom" queries:
Then I can use it like that (queries presented I thought out right now "from cosmos" - not very real ones but present possibilities that this change gives):
or like that:
or:
etc. I thought of putting this code into save method but "save" on delete query doesnt sound well. |
Thanks for this! Works perfectly for running a mass-update query (or any SQL for which you don't care about the result). |
Great solution, but how to fix log? And in ORM::get_query_log() i see ``[5] => UPDATE |
I am still not sure I see the advantage here of adding this complexity. Seems to me that using the PDO instance directly for these operations would work. I can't even really see any keystrokes being saved here. Is there something I am missing? The following code is quite neat and tidy:
If this is to make it into Idiorm's core then it needs to become a whole lot more elegant in its implementation. So that you end up with something like:
Then again maybe I am missing something that you guys are gaining by having |
@treffynnon, I think you're correct about implementation, and put something together along those lines, complete with query logging and a (somewhat farcical) unit test. |
Closed in commit f6d7861 |
I'm not sure if it should be posted as an issue or as a feature request. I have problem to use raw queries to send update query to the database. For example I need to change many rows at once with simple where condition.
It would be great if one could use it like that:
ORM::for_table('person')->raw_query('UPDATE worker SET income = :income WHERE job = :job',array('job' => $job, 'income' => $income))->save();
But save doesn't send it.
find_one / find_many runs that query, but with problems with null parameters (I had to set null and it set 0) and with PDO error at the end.
I think this feature will help those who need to update on many rows - without refactoring much in the library.
The text was updated successfully, but these errors were encountered: