You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing a problem while trying to duplicate a record with complexe associations. I have the following models (simplified):
classContentPage < ApplicationRecordhas_many:content_page_blocks,inverse_of: :content_page,dependent: :destroyendclassContentPageBlock < ApplicationRecordbelongs_to:content_pagebelongs_to:blockable,polymorphic: true,dependent: :destroy,inverse_of: :content_page_blockendclassCardBlock < ApplicationRecordhas_one:content_page_block,as: :blockable,dependent: :destroy,inverse_of: :blockableaccepts_nested_attributes_for:content_page_block,allow_destroy: truehas_one:content_page,through: :content_page_blockhas_many:cardsclass_name: "ContentPageCard",inverse_of: :card_block,dependent: :destroyend# more ApplicationRecord models for other blocks...
My goal is to duplicate a content page with all its descendants.
options={include_keys: false,include_timestamps: false,include_unsaved_changes: false,include_descendants: true,descendant_depth: 10}content_page=ContentPage.first=>#<ContentPage:0x0000000108fdae68id: 1,name: "First ContentPage">
# load descendants into memorycontent_page.content_page_blocks.map(&:blockable)content_page.content_page_blocks.first=>#<ContentPageBlock:0x00000001096c8a90id: 1,content_page_id: 1,blockable_type: "CardBlock",blockable_id: 1>
content_page.content_page_blocks.first.blockable=>#<CardBlock:0x000000010978b860id: 1,title: "First CardBlock">
encoded=URI::UID.build(content_page,options).to_scontent_page_dup=URI::UID.parse(encoded).decodecontent_page_dup=>#<ContentPage:0x00000001089c8e58id: nil,name: "First ContentPage">
# the content page is correctly duplicated 🥳content_page_dup.content_page_blocks.first=>#<ContentPageBlock:0x0000000108a30918id: nil,content_page_id: nil,blockable_type: "CardBlock",blockable_id: nil>
# the content page block is correctly duplicated as well 🥳content_page_dup.content_page_blocks.first.content_page == content_page_dup=>true# and it's correctly associated to the duplicated content page 🥳content_page_dup.content_page_blocks.first.blockable=>nil# it should be a new instance of CardBlock but it is nil... 😕
As you can see, the gem fails to duplicate the polymorphic association blockable of the ContentPageBlock model.
FYI, I'm encoutering the same problem with models that have has_many_attached and has_one_attached associations.
Thanks for your help !
The text was updated successfully, but these errors were encountered:
Hi @hopsoft !
First of all, thanks for this awesome gem !
I'm facing a problem while trying to duplicate a record with complexe associations. I have the following models (simplified):
My goal is to duplicate a content page with all its descendants.
As you can see, the gem fails to duplicate the polymorphic association
blockable
of theContentPageBlock
model.FYI, I'm encoutering the same problem with models that have
has_many_attached
andhas_one_attached
associations.Thanks for your help !
The text was updated successfully, but these errors were encountered: