Skip to content

Commit

Permalink
Add method for retrieving free staging projects
Browse files Browse the repository at this point in the history
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
2 people authored and dmarcoux committed Nov 5, 2018
1 parent 30f9bb9 commit 53f64d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/api/app/models/staging_workflow.rb
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.

Copy link
@mdeniz

mdeniz Nov 5, 2018

Contributor

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:

left_outer_joins(:staged_requests).where(bs_requests: { id: nil })

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

This comment was marked as outdated.

Copy link
@eduardoj

eduardoj Nov 13, 2018

Author Member

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:

left_outer_joins(:staged_requests).where(bs_requests: { id: nil })

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

Yes it is. I will create a PR to fix it. 👍

end
end

has_many :target_of_bs_requests, through: :project
has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects
Expand Down

0 comments on commit 53f64d2

Please sign in to comment.