Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
48671021
Commit
48671021
authored
Aug 28, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scope :in_order & :in_cart to Snapshot
parent
e002fccf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
cart.rb
lib/shotengai/cart.rb
+7
-1
order.rb
lib/shotengai/order.rb
+2
-1
snapshot.rb
lib/shotengai/snapshot.rb
+17
-1
No files found.
lib/shotengai/cart.rb
View file @
48671021
...
...
@@ -28,7 +28,13 @@ module Shotengai
class
Cart
<
::
ActiveRecord
::
Base
self
.
table_name
=
'shotengai_orders'
default_scope
{
where
(
status:
'cart'
)
}
#
# class Order < Shotengai::Order
# can_by 'Product'
# end
#
# Would let Product belongs to :order & order_cart
#
class
<<
self
def
can_buy
*
good_class_names
good_classes
=
good_class_names
.
map
{
|
name
|
Object
.
const_get
(
name
)
}
...
...
lib/shotengai/order.rb
View file @
48671021
...
...
@@ -30,7 +30,8 @@ module Shotengai
class
Order
<
ActiveRecord
::
Base
self
.
table_name
=
'shotengai_orders'
belongs_to
:buyer
,
polymorphic:
true
belongs_to
:buyer
,
polymorphic:
true
,
optional:
true
default_scope
{
where
.
not
(
status:
'cart'
)
}
include
AASM_DLC
...
...
lib/shotengai/snapshot.rb
View file @
48671021
...
...
@@ -31,7 +31,23 @@ module Shotengai
validate
:check_spec
,
if: :spec
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
belongs_to
:shotengai_order
,
optional:
true
belongs_to
:shotengai_order
,
foreign_key: :shotengai_order_id
,
class_name:
'Shotengai::Order'
,
optional:
true
scope
:in_order
,
->
{
joins
(
"
INNER JOIN shotengai_orders ON
shotengai_snapshots.shotengai_order_id = shotengai_orders.id AND
shotengai_orders.status <> 'cart'
"
)
}
scope
:in_cart
,
->
{
joins
(
"
INNER JOIN shotengai_orders ON
shotengai_snapshots.shotengai_order_id = shotengai_orders.id AND
shotengai_orders.status = 'cart'
"
)
}
class
<<
self
def
inherited
subclass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment