Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
acts_as_pasting
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
acts_as_pasting
Commits
691deee5
Commit
691deee5
authored
Aug 07, 2020
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add distinct to association
parent
da399723
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
pastable.rb
lib/acts_as_pasting/pastable.rb
+4
-4
pasted.rb
lib/acts_as_pasting/pasted.rb
+1
-1
No files found.
lib/acts_as_pasting/pastable.rb
View file @
691deee5
...
...
@@ -9,7 +9,7 @@ module ActsAsPasting
# ary => [[klass, id], [klass, id]]
# ary => [obj, obj]
scope
:past
ed
_with_any
,
->
(
ary
,
prefix:
''
)
{
scope
:past
able
_with_any
,
->
(
ary
,
prefix:
''
)
{
ary
=
parsed_condition_ary
(
ary
)
arel
=
Arel
::
Table
.
new
(
:acts_as_pasting_pastings
,
as:
"acts_as_pasting_pastings_
#{
SecureRandom
.
hex
(
10
)
}
"
)
source_arel
=
arel_table
...
...
@@ -23,10 +23,10 @@ module ActsAsPasting
joins
(
arel
.
join
(
arel
).
on
(
join_condition
).
join_sources
).
distinct
}
scope
:past
ed
_with_all
,
->
(
ary
,
prefix:
''
)
{
scope
:past
able
_with_all
,
->
(
ary
,
prefix:
''
)
{
ary
=
parsed_condition_ary
(
ary
)
ary
.
reduce
(
where
(
nil
))
do
|
association
,
value
|
association
.
past
ed
_with_any
([
value
],
prefix:
prefix
)
association
.
past
able
_with_any
([
value
],
prefix:
prefix
)
end
}
end
...
...
@@ -35,7 +35,7 @@ module ActsAsPasting
def
acts_as_pastable
associations
,
prefix:
''
,
**
options
pasting_name
=
prefix
.
blank?
?
"
#{
associations
}
_pastings"
.
to_sym
:
[
associations
,
prefix
,
'pastings'
].
join
(
'_'
).
to_sym
has_many
(
pasting_name
,
->
{
where
(
type:
prefix
)
},
as: :pasteable
,
class_name:
'ActsAsPasting::Pasting'
)
has_many
(
associations
,
through:
pasting_name
,
source: :pasted
,
**
options
)
has_many
(
associations
,
->
{
distinct
},
through:
pasting_name
,
source: :pasted
,
**
options
)
end
end
end
...
...
lib/acts_as_pasting/pasted.rb
View file @
691deee5
...
...
@@ -204,7 +204,7 @@ module ActsAsPasting
def
acts_as_pasted
associations
,
prefix:
''
,
**
options
pasting_name
=
prefix
.
blank?
?
"
#{
associations
}
_pastings"
.
to_sym
:
[
associations
,
prefix
,
'pastings'
].
join
(
'_'
).
to_sym
has_many
(
pasting_name
,
->
{
where
(
type:
prefix
)
},
class_name:
'ActsAsPasting::Pasting'
,
as: :pasted
)
has_many
(
associations
,
through:
pasting_name
,
source: :pasteable
,
**
options
)
has_many
(
associations
,
->
{
distinct
},
through:
pasting_name
,
source: :pasteable
,
**
options
)
end
end
...
...
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