-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method for retrieving free staging projects
This method retrieves the staging projects of a workflow project that don't have any requests assigned. Co-authored-by: Saray Cabrera Padrón <scabrerapadron@suse.de>
- Loading branch information
Showing
1 changed file
with
5 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
class StagingWorkflow < ApplicationRecord | ||
belongs_to :project, inverse_of: :staging | ||
has_many :staging_projects, class_name: 'Project', inverse_of: :staging_workflow, dependent: :nullify | ||
has_many :staging_projects, class_name: 'Project', inverse_of: :staging_workflow, dependent: :nullify do | ||
def without_staged_requests | ||
includes(:staged_requests).where(bs_requests: { id: nil }) | ||
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
eduardoj
Author
Member
|
||
end | ||
end | ||
|
||
has_many :target_of_bs_requests, through: :project | ||
has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects | ||
|
Isn't better if we use the recommend way of doing this in Rails 5? I mean by using
left_outer_joins
instead of includes:See:
https://solidfoundationwebdev.com/blog/posts/how-to-find-records-based-on-has_many-relationship-being-empty-or-not-in-rails
https://stackoverflow.com/questions/5319400/want-to-find-records-with-no-associated-records-in-rails-3