Sha256: b23f8d0a417cf4acdc80c6e62d724731474a5ded5d117a49785e15d32252e532

Contents?: true

Size: 579 Bytes

Versions: 9

Compression:

Stored size: 579 Bytes

Contents

# frozen_string_literal: true

class Album < ActiveRecord::Base
  self.primary_key = :id

  before_validation :set_id, :on => :create
  before_validation :set_integer_id, :on => :create

  ThinkingSphinx::Callbacks.append(
    self, :behaviours => [:sql, :real_time, :deltas]
  )

  validates :id,         :presence => true, :uniqueness => true
  validates :integer_id, :presence => true, :uniqueness => true

  private

  def set_id
    self.id = (Album.maximum(:id) || "a").next
  end

  def set_integer_id
    self.integer_id = (Album.maximum(:integer_id) || 0) + 1
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/internal/app/models/album.rb
thinking-sphinx-5.5.1 spec/internal/app/models/album.rb
thinking-sphinx-5.5.0 spec/internal/app/models/album.rb
thinking-sphinx-5.4.0 spec/internal/app/models/album.rb
thinking-sphinx-5.3.0 spec/internal/app/models/album.rb
thinking-sphinx-5.2.1 spec/internal/app/models/album.rb
thinking-sphinx-5.2.0 spec/internal/app/models/album.rb
thinking-sphinx-5.1.0 spec/internal/app/models/album.rb
thinking-sphinx-5.0.0 spec/internal/app/models/album.rb