Sha256: 7f1f6a31bd21a6557ff9baf29a4b30d255d843fe91eb909ef73a719f01718125
Contents?: true
Size: 1.65 KB
Versions: 1
Compression:
Stored size: 1.65 KB
Contents
class AnnotationValueSeed < ActiveRecord::Base validates_presence_of :attribute_id, :value_type, :value_id belongs_to :value, :polymorphic => true belongs_to :attribute, :class_name => "AnnotationAttribute", :foreign_key => "attribute_id" # Named scope to allow you to include the value records too. # Use this to *potentially* improve performance. scope :include_values, lambda { { :include => [ :value ] } } # Finder to get all annotation value seeds with a given attrib_name. scope :with_attribute_name, lambda { |attrib_name| { :conditions => { :annotation_attributes => { :name => attrib_name } }, :joins => :attribute, :order => "created_at DESC" } } # Finder to get all annotation value seeds with one of the given attrib_names. scope :with_attribute_names, lambda { |attrib_names| conditions = [attrib_names.collect{"annotation_attributes.name = ?"}.join(" or ")] | attrib_names { :conditions => conditions, :joins => :attribute, :order => "created_at DESC" } } # Finder to get all annotations for a given value_type. scope :with_value_type, lambda { |value_type| { :conditions => { :value_type => value_type }, :order => "created_at DESC" } } def self.find_by_attribute_name(attr_name) return [] if attr_name.blank? AnnotationValueSeed.find(:all, :joins => [ :attribute ], :conditions => { :annotation_attributes => { :name => attr_name } }, :order => "created_at DESC") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
my_annotations-0.6.0 | lib/app/models/annotation_value_seed.rb |