-
Notifications
You must be signed in to change notification settings - Fork 290
Description
Currently, when editing the settings for a site, a bunch of irrelevant custom field groups are being shown in the site settings. These field groups are meant to act on certain types of content owned by the site, but not on the site itself. However, since these field groups include required fields, their presence makes it impossible to save the relevant changes to my site settings because this irrelevant data is not filled in.
Steps to reproduce:
- Make a custom field group for any type of content within a site. Include a required field. In the "Where to display this group" select box, select anything besides Site settings.
- Navigate to /admin/settings/site, click on the Custom Configurations tab, and view the custom fields that should not be there.
Analysis:
The view renders a collection from Site#get_field_groups:
| <% groups = @site.get_field_groups %> |
| <%= render partial: "camaleon_cms/admin/settings/custom_fields/render", locals: {record: @site, field_groups: groups} %> |
Site#get_field_groups calls Site#custom_field_groups:
| custom_field_groups |
Site#custom_field_groups uses the foreign key CustomFieldGroup#parent_id:
camaleon-cms/app/models/camaleon_cms/site.rb
Lines 17 to 18 in 67de883
| has_many :custom_field_groups, class_name: 'CamaleonCms::CustomFieldGroup', foreign_key: :parent_id, | |
| dependent: :destroy |
And that's where I think the problem lies, because ultimately Site#get_field_groups is returning custom field groups where the site is associated as the parent, rather than as the object of the custom field group.
However, I don't know yet which course of action is most appropriate:
- Modify
Site#get_field_groupsto use the theobjectforeign key relationship, instead ofparent - Use something besides
Site#get_field_groupsin the view - Something else