Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob_thanhnd
Overview
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
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
thanhnd
venjob_thanhnd
Commits
b61c3320
Commit
b61c3320
authored
Apr 06, 2020
by
thanhnd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scope to class method
parent
cc8a60f1
Pipeline
#548
failed with stages
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
app/models/city.rb
+17
-5
No files found.
app/models/city.rb
View file @
b61c3320
...
...
@@ -2,9 +2,21 @@ class City < ApplicationRecord
belongs_to
:area
has_many
:jobs
validates_presence_of
:city_name
scope
:top_city_by_job
,
->
{
joins
(
:jobs
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
.
first
(
9
)}
scope
:top_city_by_job_nn
,
->
{
joins
(
:jobs
).
where
(
"cities.area_id = 2"
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
.
first
(
9
)}
scope
:all_city_by_job
,
->
{
joins
(
:jobs
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
}
scope
:all_city_by_job_nn
,
->
{
joins
(
:jobs
).
where
(
"cities.area_id = 2"
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
}
def
self
.
top_city_by_job
City
.
joins
(
:jobs
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
.
first
(
9
)
end
def
self
.
top_city_by_job_nn
City
.
joins
(
:jobs
).
where
(
"cities.area_id = 2"
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
.
first
(
9
)
end
def
self
.
all_city_by_job
City
.
joins
(
:jobs
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
end
def
self
.
all_city_by_job_nn
City
.
joins
(
:jobs
).
where
(
"cities.area_id = 2"
).
select
(
'cities.*, COUNT(jobs.id) as job_count'
).
group
(
'jobs.city_id'
).
order
(
:job_count
).
reverse_order
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