API v1 article_categories endpoint
This commit is contained in:
parent
e1d50e5b9c
commit
69732cca0d
6 changed files with 117 additions and 0 deletions
|
|
@ -9,6 +9,12 @@ class ArticleCategory < ApplicationRecord
|
|||
# @!attribute articles
|
||||
# @return [Array<Article>] Articles with this category.
|
||||
has_many :articles
|
||||
# @!attribute order_articles
|
||||
# @return [Array<OrderArticle>] Order articles with this category.
|
||||
has_many :order_articles, through: :articles
|
||||
# @!attribute orders
|
||||
# @return [Array<Order>] Orders with articles in this category.
|
||||
has_many :orders, through: :order_articles
|
||||
|
||||
normalize_attributes :name, :description
|
||||
|
||||
|
|
@ -16,6 +22,14 @@ class ArticleCategory < ApplicationRecord
|
|||
|
||||
before_destroy :check_for_associated_articles
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w(id name)
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
%w(articles order_articles orders)
|
||||
end
|
||||
|
||||
# Find a category that matches a category name; may return nil.
|
||||
# TODO more intelligence like remembering earlier associations (global and/or per-supplier)
|
||||
def self.find_match(category)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue