dimanche 9 décembre 2018

how to use joins query in rails?

i have two tables 1.Clients 2.Project

my model

class Project < ApplicationRecord
    belongs_to :client
end
class Client < ApplicationRecord
    has_many :projects
end

i have 3 records in my project table u can see project table https://imgur.com/a/f33McWa client table https://imgur.com/a/J62yZhf i want to display the record with client name how to write a query in my controller

My controller

class ProjectsController < ApplicationController
    def index
        @projects = #your query here
    end
end

Aucun commentaire:

Enregistrer un commentaire