-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Possible issue w/ becomes
#16269
Comments
You are not assigning title. |
@isaacsanders Sorry, bad code examples. I tried to update my "real" code with the classic |
No problem. Helps to know the example is sounds. Thanks!
|
@kyledecot it would be easier if you provide your report in the form of an executable test case. You can use this script as a starting point. |
Are you using postgresql? Here is the test, which currently doesn't pass because afaik SQLite has no built-in support for uuids: https://gist.github.com/a3gis/30bf9b5eee4da8bf3340 |
@kyledecot I gist(ed) an example sript above. The strange thing is that it works fine without the |
@A3gis I think your gist has a flaw. |
@bigxiang In the OP: "[...] I'm converting my posts table to use uuids instead of the default integers [...]", so I assume there was no |
@A3gis, ah I see what you mean. But I really can't execute the gist without |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
This passes for me on Rails master. I think the issue is that you are using SQLite for your database -- I don't think SQLite supports UUID. I think this should be closed. require File.expand_path('../../load_paths', __FILE__)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'testy')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, id: :uuid do |t|
t.string :title
end
create_table :posts_temp, id: :uuid do |t|
t.string :title
end
end
class Post < ActiveRecord::Base
end
class PostTemp < ActiveRecord::Base
self.table_name = :posts_temp
end
class BugTest < Minitest::Test
def test_stuff
post = Post.create(title: 'foobar')
post.save
assert_equal post.title, 'foobar'
post_temp = post.dup.becomes(PostTemp)
assert_equal post_temp.title, 'foobar'
assert_equal post_temp.save, true
post_temp.reload
assert_equal post_temp.title, 'foobar'
end
end |
In my migration I'm converting my
posts
table to use uuids instead of the default integers via something like the following:When running this and inspecting what
post_temp.title
is the value appears to be there. When callingpost_temp.reload
and inspecting thetitle
again however it'snil
. It seems as though the value is not being saved to the database.Is this a bug or am I doing something incorrectly here?
The text was updated successfully, but these errors were encountered: