TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.97k stars 177 forks source link

problem when creating an entity with a polymorphic relationship #491

Closed MaximShaikovskiy closed 2 months ago

MaximShaikovskiy commented 2 months ago

Hello Screenshot from 2024-09-16 15-39-33 I get this error t.references :documents_block, polymorphic: true, null: false has_many :documents, as: :documents_block, dependent: :destroy belongs_to :documents_block, polymorphic: true Trestle.resource(:documents) build_instance do |attrs, params| if params[:information_material_and_general_rule_id] scope = ::InformationMaterialAndGeneralRule .find(params[:information_material_and_general_rule_id]) .documents else scope = ::Document end scope.new(attrs) end form dialog: true do |document| if document.documents_block hidden_field :documents_block_id else select :documents_block_id, InformationMaterialAndGeneralRule.all end image gem 'trestle', '0.10.0.pre'

spohlenz commented 2 months ago

For polymorphic associations, you'll need both the _id column as well as a corresponding _type column. In order to achieve this within a single select field, you might want to look into signed GlobalID -- check out this article and this GoRails episode for some ideas on how to implement.

MaximShaikovskiy commented 2 months ago

Dull again... How to delete this issue?