Class: Dawanda::Category
- Inherits:
-
Object
- Object
- Dawanda::Category
- Includes:
- Model
- Defined in:
- lib/dawanda/category.rb
Overview
Category
Dawanda::Category are organized in a tree. To get the top level categories call top
Represents a single Dawanda::Category - has the following attributes:
- id
-
The unique identifier for this category
- parent_id
-
This category’s parent id
- name
-
This category’s name
- product_count
-
The amount of products in this category
Class Method Summary collapse
-
.top(params = {}) ⇒ Object
Get all the top level categories.
Instance Method Summary collapse
-
#children(params = {}) ⇒ Object
Get all child categories of this category.
-
#parent(params = {}) ⇒ Object
Get the parent category of this category.
-
#products(params = {}) ⇒ Object
Get all products for this category.
Methods included from Model
Class Method Details
.top(params = {}) ⇒ Object
Get all the top level categories.
31 32 33 34 35 |
# File 'lib/dawanda/category.rb', line 31 def self.top(params = {}) # This is a hack, because dynamic finder generation takes at least # one placeholder like ":name" self.find_all_by_name('top', params) end |
Instance Method Details
#children(params = {}) ⇒ Object
Get all child categories of this category
38 39 40 |
# File 'lib/dawanda/category.rb', line 38 def children(params = {}) Category.find_all_by_parent_id(id, params) end |
#parent(params = {}) ⇒ Object
Get the parent category of this category
43 44 45 |
# File 'lib/dawanda/category.rb', line 43 def parent(params = {}) (parent_id and parent_id !=0) ? Category.find_by_id(parent_id, params) : nil end |
#products(params = {}) ⇒ Object
Get all products for this category.
26 27 28 |
# File 'lib/dawanda/category.rb', line 26 def products(params = {}) @products ||= Product.find_all_by_category_id(id, params) end |