item groups now have order - start page is now item group 1 (configurable in globals)
This commit is contained in:
13
front-api/db/migrate/20150420044444_create_item_in_groups.rb
Normal file
13
front-api/db/migrate/20150420044444_create_item_in_groups.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateItemInGroups < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :item_in_groups do |t|
|
||||
t.integer :item_id
|
||||
t.integer :item_group_id
|
||||
t.integer :position
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
drop_table "item_item_groups"
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150414214540) do
|
||||
ActiveRecord::Schema.define(version: 20150420044444) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -106,9 +106,12 @@ ActiveRecord::Schema.define(version: 20150414214540) do
|
||||
t.decimal "price"
|
||||
end
|
||||
|
||||
create_table "item_item_groups", id: false, force: :cascade do |t|
|
||||
t.integer "item_id", null: false
|
||||
t.integer "item_group_id", null: false
|
||||
create_table "item_in_groups", force: :cascade do |t|
|
||||
t.integer "item_id"
|
||||
t.integer "item_group_id"
|
||||
t.integer "position"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "items", force: :cascade do |t|
|
||||
|
||||
@@ -4,6 +4,9 @@ class Item < ActiveRecord::Base
|
||||
has_many :multi_media_descriptions
|
||||
belongs_to :sub_category
|
||||
|
||||
has_many :item_groups, through: :item_in_groups
|
||||
|
||||
|
||||
attr_accessor :count # used for cart
|
||||
def attributes
|
||||
super.merge('count' => self.count)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
class ItemGroup < ActiveRecord::Base
|
||||
has_and_belongs_to_many :items, :join_table => 'item_item_groups'
|
||||
|
||||
has_many :item_in_groups
|
||||
has_many :items, through: :item_in_groups
|
||||
|
||||
def all_items(offset, limit)
|
||||
self.items.where(on_display: true).order(:created_at).limit(limit).offset(offset).all
|
||||
self.items.where(on_display: true).order("item_in_groups.position").limit(limit).offset(offset).all
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
4
front-api/models/item_in_group.rb
Normal file
4
front-api/models/item_in_group.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ItemInGroup < ActiveRecord::Base
|
||||
belongs_to :item_group
|
||||
belongs_to :item
|
||||
end
|
||||
Reference in New Issue
Block a user