don't include the _label attribute in the JSON representation of a content entry if this is an alias to belongs_to relationship

did committed Apr 06, 2017
commit 0209de9d6bea027ec2f57dfb5cf33dac5475bf03
Showing 2 changed files with 8 additions and 3 deletions
locomotive/steam/entities/content_entry.rb b/lib/locomotive/steam/entities/content_entry.rb +6 -1
@@ @@ -80,7 +80,12 @@ module Locomotive::Steam
hash = {}
# default attributes
- _attributes = %i(_id _slug _label _visible _position content_type_slug created_at updated_at)
+ _attributes = %i(_id _slug _visible _position content_type_slug created_at updated_at)
+
+ # stack level too deep raised if the _label field is an association (belongs_to, ...etc)
+ unless content_type.fields_by_name[content_type.label_field_name].is_relationship?
+ _attributes << :_label
+ end
# dynamic attributes
_attributes += content_type.persisted_field_names
spec/unit/entities/content_entry_spec.rb +2 -2
@@ @@ -72,7 +72,7 @@ describe Locomotive::Steam::ContentEntry do
describe '#to_hash' do
- let(:fields) { [instance_double('TitleField', name: :title, type: :string), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
+ let(:fields) { [instance_double('TitleField', name: :title, type: :string, is_relationship?: false), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
let(:attributes) { { id: 42, title: 'Hello world', _slug: 'hello-world', picture: Locomotive::Steam::Models::I18nField.new(:picture, fr: 'foo.png', en: 'bar.png'), custom_fields_recipe: ['hello', 'world'], _type: 'Entry' } }
subject { content_entry.to_hash }
@@ @@ -101,7 +101,7 @@ describe Locomotive::Steam::ContentEntry do
describe '#as_json' do
- let(:fields) { [instance_double('TitleField', name: :title, type: :string), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
+ let(:fields) { [instance_double('TitleField', name: :title, type: :string, is_relationship?: false), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
let(:attributes) { { id: 42, title: 'Hello world', _slug: 'hello-world', picture: Locomotive::Steam::Models::I18nField.new(:picture, fr: 'foo.png', en: 'bar.png'), custom_fields_recipe: ['hello', 'world'], _type: 'Entry' } }
let(:decorated) { Locomotive::Steam::Decorators::I18nDecorator.new(content_entry, :fr, :en) }