class Manifest.Model extends ManifestBase.Base set_default: () -> super @json.attributes ||= {} @json.associations ||= {} @json.table_name ||= Manifest.manifest().pluralize(@name) @json.attributes.id = { 'type': 'number', 'primary_key': 1, 'rules': { 'number': true } } @json.attributes.created_at = { 'type': 'datetime', } @json.attributes.updated_at = { 'type': 'datetime', } init: () -> super @table_name = @json.table_name @attributes = ManifestBase.load_name_values this, @json, 'attributes', Manifest.ModelModule.Attribute @associations = ManifestBase.load_value this, @json, 'associations', Manifest.ModelModule.Association item_name: () -> @name classify: () -> Manifest.item_name_to_model @name valid_encode_columns: () -> r = [] _.each @attributes, (attribute, attribute_name) -> next if not attribute.type == 'text' r.push attribute_name r owner_type: () -> return 'author' if @attributes.author_id return 'artist' if @attributes.artist_id false content_model: () -> return true if @owner_type false child_model_manifests: () -> r = [] _.each Manifest.manifest().items, (peta_manifest, peta_name) => return if not peta_manifest.is_element() return if peta_manifest.parent_item_name != @name r.push Manifest.manifest().models[peta_name] r child_models: () -> _.map @child_model_manifests(), (child_model_manifest) -> child_model_manifest.classify() child_element_names: () -> _.map @child_models(), (child_model) -> @associations.child_element_name(child_model) child_element_name: (item_name) -> @associations.child_element_name(@child_model_manifest()) class Manifest.ModelModule