Skip to content
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

Using belongs_to in attach_fields causes error #3248

Open
rctneil opened this issue Sep 15, 2024 · 0 comments
Open

Using belongs_to in attach_fields causes error #3248

rctneil opened this issue Sep 15, 2024 · 0 comments

Comments

@rctneil
Copy link
Contributor

rctneil commented Sep 15, 2024

Describe the bug

When using a belongs_to field inside attach_fields
Screenshot 2024-09-15 at 10 20 23

I'm assuming it's because the join table record does not exist at that point? That's my guess anyway!

attach_fields:

                    attach_fields: -> {
                        field :role, as: :text
                        field :companyable_type, as: :hidden,
                            default: "Attraction" # Hardcode type to ensure the polymorphic has_many :through works.
                        field :model, as: :belongs_to, use_resource: Avo::Resources::Model
                    }

Companyable:

  class Companyable < ApplicationRecord
    belongs_to :company
    belongs_to :companyable, polymorphic: true
    belongs_to :model, optional: true

Model:

class Model < ApplicationRecord
  has_many :companyables
  has_many :submodels
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant