1

This is the code I currently have:

project_ids = ProjectEnrollment.unscoped.where(user: self).pluck(:project_id)
Project.where(id: project_ids)

I'm sure there has to be a better way. Thanks!

Edit: I'm already using the method from the has_many relationship, with scoped projects for another case.

1 Answer 1

1

In your User model:

has_many :project_enrollments, -> { unscoped }
has_many :projects, through: :project_enrollments

In your ProjectEnrollment model:

belongs_to :user
belongs_to :project

Then you can do

user.projects

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I guess I could have been clearer on my question, I'll edit. I'm already using the scoped method for something else. But this is definitely on the right track.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.