Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/subroutine/association_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def field_with_association(field_name, options = {})
if options[:type]&.to_sym == :association
config = ::Subroutine::AssociationFields::Configuration.new(field_name, options)

field_without_association(config.as, config)

if config.polymorphic?
field config.foreign_type_method, config.build_foreign_type_field
else
Expand All @@ -77,8 +79,6 @@ def field_with_association(field_name, options = {})
end

field config.foreign_key_method, config.build_foreign_key_field

field_without_association(config.as, config)
else
field_without_association(field_name, options)
end
Expand Down
1 change: 1 addition & 0 deletions lib/subroutine/association_fields/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def build_child_field(name, opts = {})
child_opts = inheritable_options
child_opts.merge!(opts)
child_opts[:association_name] = as
child_opts[:allow_override] = true
ComponentConfiguration.new(name, child_opts)
end

Expand Down
7 changes: 7 additions & 0 deletions lib/subroutine/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
module Subroutine
module Fields

DuplicateFieldError = Class.new(StandardError)

extend ActiveSupport::Concern

def self.allowed_input_classes
Expand All @@ -30,6 +32,11 @@ def self.action_controller_params_loaded?
module ClassMethods

def field(field_name, options = {})

if field_configurations.key?(field_name.to_sym) && !options[:allow_override]
raise DuplicateFieldError, "#{field_name} is already defined on #{self}. Add `allow_override: true` to reconfigure the field."
end

config = ::Subroutine::Fields::Configuration.from(field_name, options)
config.validate!

Expand Down
6 changes: 3 additions & 3 deletions lib/subroutine/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Subroutine

MAJOR = 4
MINOR = 5
MAJOR = 5
MINOR = 0
PATCH = 0
PRE = nil
PRE = "alpha"

VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")

Expand Down
4 changes: 2 additions & 2 deletions test/support/ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class OnlyFooBarOp < ::Subroutine::Op

class InheritedDefaultsOp < ::DefaultsOp

field :bar, default: "barstool", allow_overwrite: true
field :bar, default: "barstool", allow_override: true

end

Expand Down Expand Up @@ -354,7 +354,7 @@ class SimpleAssociationWithStringIdOp < ::OpWithAssociation

class UnscopedSimpleAssociationOp < ::OpWithAssociation

association :user, unscoped: true, allow_overwrite: true
association :user, unscoped: true, allow_override: true

end

Expand Down