class Peta.ElementNestableContent extends Peta.Content element_items: (element_model) -> n = @my_class().my_manifest().associations.child_element_name(element_model) @get(n) elements_items: () -> r = _.map @my_class().child_models(), (element_model) => @element_items(element_model) _.compact(_.flatten(r)) boosts: (level) -> super(level) _.each @elements_items(), (item) => item.boosts(level) if item replaced_attributes: () -> attributes = {} _.each @attributes, (attribute, name) => replaced = if _.isArray(attribute) # has many association model = @my_class().my_manifest().associations.has_many[name].model() _.map attribute, (attr) => child = @replace_element(model, attr) child.attributes = child.replaced_attributes() child else if _.isObject(attribute) # has one association model = @my_class().my_manifest().associations.has_one[name].model() child = @replace_element(model, attribute) child.attributes = child.replaced_attributes() child else attribute attributes[name] = replaced attributes replace_element: (model, attr) -> empty_child = new model(attr) cached_child = Pettanr.cache.restore(empty_child) Pettanr.cache.store(empty_child) if !cached_child cached_child || empty_child