Class: ApplicationRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/application_record.rb

Direct Known Subclasses

AbuseReport, AlertManagement::Alert, AlertManagement::AlertAssignee, Alerting::ProjectAlertingSetting, AlertsServiceData, Analytics::CycleAnalytics::ProjectStage, Analytics::InstanceStatistics::Measurement, Appearance, ApplicationSetting, ApplicationSetting::Term, Approval, Atlassian::Identity, AuditEvent, AuditEventPartitioned, AwardEmoji, Aws::Role, Badge, Board, BoardGroupRecentVisit, BoardProjectRecentVisit, BroadcastMessage, ChatName, ChatTeam, Ci::BuildMetadata, Ci::BuildNeed, Ci::BuildPendingState, Ci::BuildReportResult, Ci::BuildRunnerSession, Ci::BuildTraceChunk, Ci::BuildTraceSection, Ci::BuildTraceSectionName, Ci::DailyBuildGroupReportResult, Ci::FreezePeriod, Ci::GroupVariable, Ci::InstanceVariable, Ci::JobArtifact, Ci::JobVariable, Ci::Pipeline, Ci::PipelineArtifact, Ci::PipelineChatData, Ci::PipelineConfig, Ci::PipelineMessage, Ci::PipelineSchedule, Ci::PipelineScheduleVariable, Ci::PipelineVariable, Ci::Ref, Ci::Resource, Ci::ResourceGroup, Ci::Runner, Ci::RunnerNamespace, Ci::RunnerProject, Ci::Sources::Pipeline, Ci::Stage, Ci::Trigger, Ci::TriggerRequest, Ci::Variable, CiPlatformMetric, Clusters::Agent, Clusters::AgentToken, Clusters::Applications::CertManager, Clusters::Applications::Cilium, Clusters::Applications::Crossplane, Clusters::Applications::ElasticStack, Clusters::Applications::Fluentd, Clusters::Applications::Helm, Clusters::Applications::Ingress, Clusters::Applications::Jupyter, Clusters::Applications::Knative, Clusters::Applications::Prometheus, Clusters::Applications::Runner, Clusters::Cluster, Clusters::Group, Clusters::KubernetesNamespace, Clusters::Platforms::Kubernetes, Clusters::Project, Clusters::Providers::Aws, Clusters::Providers::Gcp, CommitStatus, ContainerExpirationPolicy, ContainerRepository, CustomEmoji, DeployKeysProject, DeployToken, Deployment, DeploymentCluster, DeploymentMergeRequest, DescriptionVersion, DesignManagement::Action, DesignManagement::Design, DesignManagement::Version, DevOpsReport::Metric, DiffNotePosition, DraftNote, Email, Environment, Epic, ErrorTracking::ProjectErrorTrackingSetting, Event, Experiment, ExperimentUser, ExternalPullRequest, ForkNetwork, ForkNetworkMember, Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData::IssueTrackerData, Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData::JiraTrackerData, Gitlab::Database::PartitioningMigrationHelpers::PartitionedForeignKey, Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetric, GpgKey, GpgKeySubkey, GpgSignature, GrafanaIntegration, GroupCustomAttribute, GroupDeployKeysGroup, GroupDeployToken, GroupGroupLink, GroupImportState, Identity, ImportExportUpload, ImportFailure, IncidentManagement::ProjectIncidentManagementSetting, InternalId, IssuableSeverity, Issue, Issue::Metrics, IssueAssignee, IssueLink, IssueTrackerData, Iteration, JiraConnectInstallation, JiraConnectSubscription, JiraImportState, JiraTrackerData, Key, Label, LabelLink, LabelPriority, LfsFileLock, LfsObject, LfsObjectsProject, List, ListUserPreference, Member, MergeRequest, MergeRequest::Metrics, MergeRequestAssignee, MergeRequestContextCommit, MergeRequestContextCommitDiffFile, MergeRequestDiff, MergeRequestDiffCommit, MergeRequestDiffFile, MergeRequestReviewer, MergeRequestsClosingIssues, Metrics::Dashboard::Annotation, Metrics::UsersStarredDashboard, Milestone, MilestoneRelease, Namespace, Namespace::AggregationSchedule, Namespace::RootStorageStatistics, NamespaceSetting, Note, NoteDiffFile, NotificationSetting, OpenProjectTrackerData, Operations::FeatureFlag, Operations::FeatureFlagScope, Operations::FeatureFlags::Scope, Operations::FeatureFlags::Strategy, Operations::FeatureFlags::StrategyUserList, Operations::FeatureFlags::UserList, Operations::FeatureFlagsClient, Packages::BuildInfo, Packages::Composer::Metadatum, Packages::Conan::FileMetadatum, Packages::Conan::Metadatum, Packages::Dependency, Packages::DependencyLink, Packages::Maven::Metadatum, Packages::Nuget::DependencyLinkMetadatum, Packages::Nuget::Metadatum, Packages::Package, Packages::PackageFile, Packages::Pypi::Metadatum, Packages::Tag, PagesDomain, PagesDomainAcmeOrder, PersonalAccessToken, Plan, PlanLimits, PoolRepository, Postgresql::ReplicationSlot, ProductAnalyticsEvent, ProgrammingLanguage, Project, ProjectAuthorization, ProjectAutoDevops, ProjectCiCdSetting, ProjectCustomAttribute, ProjectDailyStatistic, ProjectDeployToken, ProjectExportJob, ProjectFeature, ProjectFeatureUsage, ProjectGroupLink, ProjectImportData, ProjectImportState, ProjectMetricsSetting, ProjectPagesMetadatum, ProjectRepository, ProjectRepositoryStorageMove, ProjectSetting, ProjectStatistics, PrometheusAlert, PrometheusAlertEvent, PrometheusMetric, ProtectedBranch, ProtectedBranch::MergeAccessLevel, ProtectedBranch::PushAccessLevel, ProtectedTag, ProtectedTag::CreateAccessLevel, PushEventPayload, RawUsageData, RedirectRoute, Release, Releases::Evidence, Releases::Link, RemoteMirror, RepositoryLanguage, ResourceEvent, Review, Route, SelfManagedPrometheusAlertEvent, SentNotification, SentryIssue, Serverless::DomainCluster, Service, ServiceDeskSetting, Shard, Snippet, SnippetRepository, SnippetStatistics, SpamLog, Subscription, Suggestion, SystemNoteMetadata, TermAgreement, Terraform::State, Timelog, Todo, TrendingProject, U2fRegistration, Upload, User, UserAgentDetail, UserCallout, UserCanonicalEmail, UserCustomAttribute, UserDetail, UserHighestRole, UserInteractedProject, UserMention, UserPreference, UserStatus, UserSyncedAttributesMetadata, UsersStarProject, UsersStatistics, WebHook, WebHookLog, WebauthnRegistration, WikiPage::Meta, WikiPage::Slug, X509Certificate, X509CommitSignature, X509Issuer, ZoomMeeting

Class Method Summary collapse

Class Method Details

.at_most(count) ⇒ Object


45
46
47
# File 'app/models/application_record.rb', line 45

def self.at_most(count)
  limit(count)
end

.id_in(ids) ⇒ Object


12
13
14
# File 'app/models/application_record.rb', line 12

def self.id_in(ids)
  where(id: ids)
end

.id_not_in(ids) ⇒ Object


24
25
26
# File 'app/models/application_record.rb', line 24

def self.id_not_in(ids)
  where.not(id: ids)
end

.iid_in(iids) ⇒ Object


20
21
22
# File 'app/models/application_record.rb', line 20

def self.iid_in(iids)
  where(iid: iids)
end

.pluck_primary_keyObject


28
29
30
# File 'app/models/application_record.rb', line 28

def self.pluck_primary_key
  where(nil).pluck(self.primary_key)
end

.primary_key_in(values) ⇒ Object


16
17
18
# File 'app/models/application_record.rb', line 16

def self.primary_key_in(values)
  where(primary_key => values)
end

.safe_ensure_unique(retries: 0) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/application_record.rb', line 32

def self.safe_ensure_unique(retries: 0)
  transaction(requires_new: true) do
    yield
  end
rescue ActiveRecord::RecordNotUnique
  if retries > 0
    retries -= 1
    retry
  end

  false
end

.safe_find_or_create_by(*args, &block) ⇒ Object


55
56
57
58
59
# File 'app/models/application_record.rb', line 55

def self.safe_find_or_create_by(*args, &block)
  safe_ensure_unique(retries: 1) do
    find_or_create_by(*args, &block)
  end
end

.safe_find_or_create_by!(*args, &block) ⇒ Object


49
50
51
52
53
# File 'app/models/application_record.rb', line 49

def self.safe_find_or_create_by!(*args, &block)
  safe_find_or_create_by(*args, &block).tap do |record|
    record.validate! unless record.persisted?
  end
end

.underscoreObject


61
62
63
# File 'app/models/application_record.rb', line 61

def self.underscore
  Gitlab::SafeRequestStore.fetch("model:#{self}:underscore") { self.to_s.underscore }
end

.without_orderObject


8
9
10
# File 'app/models/application_record.rb', line 8

def self.without_order
  reorder(nil)
end