Sha256: 82bcb544b929728f62c45aa9e8b28061df946d412e89310f78d345b5f07be999

Contents?: true

Size: 484 Bytes

Versions: 5

Compression:

Stored size: 484 Bytes

Contents

class MagicFieldRelationship < ActiveRecord::Base
  belongs_to :magic_field
  belongs_to :owner, :polymorphic => true
  #belongs_to :extended_model, :polymorphic => true
  validates_uniqueness_of :name, scope: [:owner_id, :owner_type, :type_scoped]
  validates_presence_of :name, :type_scoped

  before_validation :sync_name

  def sync_name
    self.name = magic_field.name
    self.type_scoped = magic_field.type_scoped.blank? ? self.owner_type : magic_field.type_scoped
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
has_magic_fields-0.2.1 lib/app/models/magic_field_relationship.rb
has_magic_fields-0.2.0 lib/app/models/magic_field_relationship.rb
has_magic_fields-0.1.2 lib/app/models/magic_field_relationship.rb
has_magic_fields-0.1.0 lib/app/models/magic_field_relationship.rb
has_magic_fields-0.0.1 lib/app/models/magic_field_relationship.rb