I’m having a really hard time figuring out what’s wrong with this
scenario.
Here’s my setup
My classes and their relationships…
class Document < ActiveRecord::Base
has_many :attachments, :dependent => :destroy
end
class Page < Document
end
class Entry < Document
end
class Attachment < ActiveRecord::Base
belongs_to :document
end
Then I’ve been trying this code [roughly]
@document = Page.find(1) # Assume there’s a record and not nil.
@document.attachments # => []
@document.attachments.create(params)
@document.attachments # => [an_attachment]
But the minute I reload…
@document = Page.find(1) # Reload that page!
@document.attachments # => [] again!
It looks like my attachment isn’t ever getting a value for “document_id”
during the creation process. The attachment is created but just sits
there
alone floating in space. I also tried polymorphic but that didn’t do any
better. Here’s the setup I used for polymorphic…
class Document < ActiveRecord::Base
has_many :attachments, :as => :attachable, :dependent => :destroy
end
class Page < Document
end
class Entry < Document
end
class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
end
Help!? Thanks in advance!
RSL