I would just like to understand rails scopes. Any good explanation would be helpful.
- I am trying to display only users who have resumes that have employments
I used a scope to try and display this:
scope :resumes_with_employments, -> { where("id in (select resume_id from employments)") }I have 2 users. They both have a resume with employments but yet only one user is being displayed.
models
user.rb
has_one :resume
resume.rb
belongs_to :user
has_many :employments
employment.rb
belongs_to :resume
schema
create_table "users", force: true do |t|
t.string "email",
t.string "firstname"
t.string "lastname"
t.string "city"
end
create_table "resumes", force: true do |t|
t.string "address"
t.string "postcode"
t.text "summary"
t.integer "user_id"
end
create_table "employments", force: true do |t|
t.string "companyname"
t.date "datestart"
t.date "dateend"
t.integer "resume_id"
t.string "employer_name"
t.string "employer_tel"
t.string "employer_address"
t.string "employer_location"
t.string "employer_city"
t.string "employer_postcode"
t.string "employer_email"
end