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 · 5 comments
Open

Using belongs_to in attach_fields causes error #3248

rctneil opened this issue Sep 15, 2024 · 5 comments
Labels

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
Copy link
Contributor

github-actions bot commented Oct 1, 2024

This issue has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Oct 1, 2024
@rctneil
Copy link
Contributor Author

rctneil commented Oct 1, 2024

Do you have a comment on this? I really would love to be able to use a belongs_to field here in order to be able to select a record via a dropdown.

@Paul-Bob Paul-Bob removed the Stale label Oct 1, 2024
@Paul-Bob
Copy link
Contributor

Paul-Bob commented Oct 1, 2024

Hey @rctneil we would merge a PR that adds belongs_to support for attach_fields. I'll also have a look

@adrianthedev
Copy link
Collaborator

Which resource has that attach_fields option? Can you please add the whole configuration?

Copy link
Contributor

This issue has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: To Do
Development

No branches or pull requests

3 participants