Models

The models in Decidim are just plain ActiveRecord models, so you can use all the methods that come with it.

A model class example would be:

# frozen_string_literal: true

# app/models/decidim/my_module/my_resource.rb
module Decidim
  module MyModule
    class MyResource < Decidim::MyModule::ApplicationRecord
      include Decidim::HasComponent
      include Decidim::Traceable
      include Decidim::Loggable
      include Decidim::Authorable
      include Decidim::TranslatableResource
    end
  end
end

Scopes

Within core provided classes there are no default_scopes.

Validations

All the validations are defined in the models themselves.

Callbacks

The number of the callbacks is reduced to the minimum.

Concerns

The concerns are used to share code between models. They are located in app/models/concerns.

Most commonly used concerns are:

Module specific concerns

  • Decidim::Comments::Commentable

  • Decidim::Comments::CommentableWithComponent

  • Decidim::Comments::HasAvailabilityAttributes

  • Decidim::Forms::HasQuestionnaire

  • Decidim::Initiatives::HasArea

  • Decidim::Initiatives::InitiativeSlug

  • Decidim::Proposals::CommentableCollaborativeDraft

  • Decidim::Proposals::CommentableProposal

  • Decidim::Proposals::ParticipatoryTextSection

  • Decidim::Proposals::Valuatable

  • Decidim::Templates::Templatable

More information