has_one with polymorphic association not setting type in Rails 3.1.0 ? #1524

Closed
fabrizioq opened this Issue Jun 7, 2011 · 1 comment

Projects

None yet

2 participants

@fabrizioq

Given:

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
end

class Employee < ActiveRecord::Base
  has_one :picture, :as => :imageable
end

Then:

picture = Picture.new
picture.name = "my_picture"
picture.save!

employee = Employee.new
employee.picture = picture
employee.save!

employee.picture.imageable_type

Up to Rails.3.0.8.rc2 :

=> "Employee"

However, in Rails3.1.0 edge today (June 7) :

=> nil

Is this the intended behavior? Perhaps I'm missing something... please double-check.

@jonleighton jonleighton added a commit that closed this issue Jun 7, 2011
@jonleighton jonleighton Allow polymorphic has_one to work when the association is set before …
…the owner has been saved. Fixes #1524.
f5f020b
@jonleighton
Member

Thanks for the report, I've fixed this now.

@smartinez87 smartinez87 pushed a commit to smartinez87/rails that referenced this issue Jun 8, 2011
@jonleighton jonleighton Allow polymorphic has_one to work when the association is set before …
…the owner has been saved. Fixes #1524.
7d1782a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment