Sha256: 01b1de60920887793a7385ddfb7f00e31e9996e926d854990e139d29e0e7dbfb
Contents?: true
Size: 817 Bytes
Versions: 7
Compression:
Stored size: 817 Bytes
Contents
class Tag < ActiveRecord::Base has_many :taggings, :dependent => :destroy validates_presence_of :name validates_uniqueness_of :name named_scope :named, lambda { |name| { :conditions => ["name = ?", name] } } named_scope :named_like, lambda { |name| { :conditions => ["name LIKE ?", "%#{name}%"] } } named_scope :named_like_any, lambda { |list| { :conditions => list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR ") } } # LIKE is used for cross-database case-insensitivity def self.find_or_create_with_like_by_name(name) find(:first, :conditions => ["name LIKE ?", name]) || create(:name => name) end def ==(object) super || (object.is_a?(Tag) && name == object.name) end def to_s name end def count read_attribute(:count).to_i end end
Version data entries
7 entries across 7 versions & 2 rubygems