lib/subj_models/nomenclature.rb in subj_models-0.4.2 vs lib/subj_models/nomenclature.rb in subj_models-0.4.3
- old
+ new
@@ -20,11 +20,11 @@
has_many :nomenclature_photos, dependent: :destroy
has_many :nomenclature_reviews, dependent: :destroy
has_many :nomenclature_files, dependent: :destroy
has_many :events
has_many :attribute_values, dependent: :destroy
- has_many :nomenclature_prices
+ has_many :nomenclature_prices, dependent: :destroy
belongs_to :analog_related_nomenclature, class_name: "Nomenclature"
has_many :analogs, foreign_key: "analog_related_nomenclature_id", class_name: "Nomenclature"
belongs_to :bought_together_related_nomenclature, class_name: "Nomenclature"
has_many :bought_together, foreign_key: "bought_together_related_nomenclature_id", class_name: "Nomenclature"
@@ -36,10 +36,11 @@
scope :with_category, -> { where.not(category_id: nil) }
scope :brand_line_ids, -> (brand_line_id) { where(brand_line_id: brand_line_id) }
scope :with_action, -> { joins(:actions).distinct }
scope :is_recommended, -> condition { where(is_recommended: condition) }
+ scope :in_index_list, -> condition { where(show_on_index: condition) }
scope :is_stock, -> (condition) do
nomenclature_prices_join.joins("LEFT OUTER JOIN qualities ON qualities.id = nomenclature_prices.quality_id").where("qualities.is_stock" => condition)
end
scope :bought_together_external_id, -> (ids) do
@@ -122,13 +123,18 @@
scope :nomenclature_ids, -> (ids) { where(id: ids) }
scope :brand_ids, -> (brand) do
return all unless brand.present?
- joins(:brand_line).where(brand_lines: { brand_id: brand }) #TODO join brands in two ways
+ where(brand: brand)
end
+ scope :with_brand, -> (brand) do
+ return none unless brand.present?
+ where(brand: brand)
+ end
+
scope :brand_line_ids, -> (ids) do
return all unless ids.present?
where(brand_line_id: ids)
end
@@ -141,10 +147,10 @@
.where("nomenclatures.id IN (?)", self.id)
.where(user_id: user_id).any?
end
def to_s
- id.to_s # TODO
+ name.to_s # TODO
end
def self.name_field_update(field)
if field.to_s == 'name' #TODO refactor this
field = 'name.raw'
\ No newline at end of file