This project is archived and is in readonly mode.
[Patch] ActiveRecord::Timestamp#touch still fails when no updated_at/on column is present
Reported by Lars Kuhnt | August 24th, 2010 @ 12:12 PM | in 3.0.2
Hi,
ActiveRecord::Timestamp#touch generates malformed SQL when the models table misses an updated_at/on column.
For example, when I execute
Game.first.touch
the following error is raised:
games.
ActiveRecord::StatementInvalid: Mysql2::Error: 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 'WHERE
(id
= 1)' at line 1: UPDATE
games
SET WHERE (games
.id
=
1)
Shouldnt #touch in this case just return false instead of raising an error?
This is especially a problem with polymorphic associations, i.e.
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true, :touch => true
end
does not work when one of the commentable models misses the updated_at/on column.
Regards
Lars
Comments and changes to this ticket
-
Neeraj Singh August 24th, 2010 @ 02:46 PM
- Milestone set to 3.x
- State changed from new to open
- Assigned user set to Neeraj Singh
- Importance changed from to Low
-
Neeraj Singh August 24th, 2010 @ 02:58 PM
- Assigned user changed from Neeraj Singh to José Valim
- Tag changed from activerecord, timestamps, touch to activerecord, patch, timestamps, touch
Attached is code with test patch.
-
Repository August 24th, 2010 @ 03:26 PM
- State changed from open to resolved
(from [747e0744dd61561c27ae1b65a74a2b7da7e3f2fe]) @user.touch should not fail if User does not have updated_at/updated_on column.
[#5439 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/747e0744dd61561c27ae1b65a74a2b... -
Repository August 24th, 2010 @ 03:27 PM
(from [aa384de7dd302ccafdfea9963e7b12427c1009e1]) @user.touch should not fail if User does not have updated_at/updated_on column.
[#5439 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/aa384de7dd302ccafdfea9963e7b12... -
Troels Petersen September 23rd, 2010 @ 07:20 PM
The patch seems to do the opposite of what was intended:
def touch(name = nil)
attributes = timestamp_attributes_for_update_in_model unless attributes.blank? attributes << name if name ...
For a model without an :updated_xx attribute, the attributes variable will be blank, so touch(:other_attribute) does nothing.
I think you need to interchange the lines
unless attributes.blank?
attributes << name if name
-
Troels Petersen September 24th, 2010 @ 06:56 PM
- Title changed from ActiveRecord::Timestamp#touch fails when no updated_at/on column is present to [Patch] ActiveRecord::Timestamp#touch still fails when no updated_at/on column is present
Here is a patch to restore the behavior of touch on an arbitrary (date or datetime) attribute.
The point is that since touch has been generalized to update any given attribute, it should do so whether or not the model also has an updated_xx attribute.
-
José Valim September 24th, 2010 @ 07:00 PM
- Milestone cleared.
- State changed from resolved to open
I agree with the patch. I will apply it next week when I give another pass at LH.
-
Repository September 24th, 2010 @ 07:46 PM
- State changed from open to resolved
(from [55b6fa9370dbdac23b0df2bbcb70b2e2d604b410]) restore behavior of touch for models without :updated_xx [#5439 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/55b6fa9370dbdac23b0df2bbcb70b2... -
Repository September 24th, 2010 @ 07:50 PM
(from [bdba74819c6ee5a56d47afedcd7b1ae30e2e0924]) restore behavior of touch for models without :updated_xx [#5439 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/bdba74819c6ee5a56d47afedcd7b1a...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 5439 ActiveRecord::Timestamp#touch fails when no updated_at/on column is present [#5439 state:resolved]
- 5439 ActiveRecord::Timestamp#touch fails when no updated_at/on column is present [#5439 state:resolved]
- 5439 [Patch] ActiveRecord::Timestamp#touch still fails when no updated_at/on column is present (from [55b6fa9370dbdac23b0df2bbcb70b2e2d604b410]) restore...
- 5439 [Patch] ActiveRecord::Timestamp#touch still fails when no updated_at/on column is present (from [bdba74819c6ee5a56d47afedcd7b1ae30e2e0924]) restore...