Sha256: ff61f0b9cd2ae13dad17479d58dbc4cc3e2335cfcbea2e476895399c92e1d9e1

Contents?: true

Size: 431 Bytes

Versions: 5

Compression:

Stored size: 431 Bytes

Contents

module Spina
  class Resource < ApplicationRecord
    extend Mobility

    has_many :pages, dependent: :restrict_with_exception

    translates :slug, backend: :jsonb

    def pages
      case order_by
      when "title"
        super.joins(:translations).where(spina_page_translations: {locale: I18n.locale}).order("spina_page_translations.title")
      else
        super.order(created_at: :desc)
      end
    end
    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spina-2.0.2 app/models/spina/resource.rb
spina-2.0.1 app/models/spina/resource.rb
spina-2.0.0 app/models/spina/resource.rb
spina-2.0.0.beta app/models/spina/resource.rb
spina-2.0.0.alpha app/models/spina/resource.rb