Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
98a5976b
Commit
98a5976b
authored
Mar 29, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document ApplicationRecord / pluck_primary_key
We also enable the rubocop that makes it mandatory
parent
0d26c483
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
2 deletions
+31
-2
.rubocop.yml
.rubocop.yml
+14
-0
doc/development/sql.md
doc/development/sql.md
+15
-0
lib/tasks/tokens.rake
lib/tasks/tokens.rake
+1
-1
scripts/insert-rspec-profiling-data
scripts/insert-rspec-profiling-data
+1
-1
No files found.
.rubocop.yml
View file @
98a5976b
...
@@ -146,6 +146,20 @@ Naming/FileName:
...
@@ -146,6 +146,20 @@ Naming/FileName:
-
XSS
-
XSS
-
GRPC
-
GRPC
Rails/ApplicationRecord
:
Enabled
:
true
Exclude
:
# Models in database migrations should not subclass from ApplicationRecord
# as they need to be as decoupled from application code as possible
-
db/**/*.rb
-
lib/gitlab/background_migration/**/*.rb
-
lib/gitlab/database/**/*.rb
-
spec/**/*.rb
-
ee/db/**/*.rb
-
ee/lib/gitlab/background_migration/**/*.rb
-
ee/lib/ee/gitlab/background_migration/**/*.rb
-
ee/spec/**/*.rb
# GitLab ###################################################################
# GitLab ###################################################################
Gitlab/ModuleWithInstanceVariables
:
Gitlab/ModuleWithInstanceVariables
:
...
...
doc/development/sql.md
View file @
98a5976b
...
@@ -155,6 +155,21 @@ The _only_ time you should use `pluck` is when you actually need to operate on
...
@@ -155,6 +155,21 @@ The _only_ time you should use `pluck` is when you actually need to operate on
the values in Ruby itself (e.g. write them to a file). In almost all other cases
the values in Ruby itself (e.g. write them to a file). In almost all other cases
you should ask yourself "Can I not just use a sub-query?".
you should ask yourself "Can I not just use a sub-query?".
In line with our
`CodeReuse/ActiveRecord`
cop, you should only use forms like
`pluck(:id)`
or
`pluck(:user_id)`
within model code. In the former case, you can
use the
`ApplicationRecord`
-provided
`.pluck_primary_key`
helper method instead.
In the latter, you should add a small helper method to the relevant model.
## Inherit from ApplicationRecord
Most models in the GitLab codebase should inherit from
`ApplicationRecord`
,
rather than from
`ActiveRecord::Base`
. This allows helper methods to be easily
added.
An exception to this rule exists for models created in database migrations. As
these should be isolated from application code, they should continue to subclass
from
`ActiveRecord::Base`
.
## Use UNIONs
## Use UNIONs
UNIONs aren't very commonly used in most Rails applications but they're very
UNIONs aren't very commonly used in most Rails applications but they're very
...
...
lib/tasks/tokens.rake
View file @
98a5976b
...
@@ -24,7 +24,7 @@ namespace :tokens do
...
@@ -24,7 +24,7 @@ namespace :tokens do
end
end
end
end
class
TmpUser
<
ActiveRecord
::
Base
class
TmpUser
<
ActiveRecord
::
Base
# rubocop:disable Rails/ApplicationRecord
include
TokenAuthenticatable
include
TokenAuthenticatable
self
.
table_name
=
'users'
self
.
table_name
=
'users'
...
...
scripts/insert-rspec-profiling-data
View file @
98a5976b
...
@@ -22,7 +22,7 @@ module RspecProfiling
...
@@ -22,7 +22,7 @@ module RspecProfiling
ENV
[
'RSPEC_PROFILING_POSTGRES_URL'
]
ENV
[
'RSPEC_PROFILING_POSTGRES_URL'
]
end
end
class
Result
<
ActiveRecord
::
Base
class
Result
<
ActiveRecord
::
Base
# rubocop:disable Rails/ApplicationRecord
acts_as_copy_target
acts_as_copy_target
end
end
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