+1 vote
in Ruby by
A Rails project has ActiveRecord classes defined for Classroom and Student. If instances of these classes are related so that students are assigned the ID of one particular classroom, which choice shows the correct associations to define?

 A.

class Classroom < ActiveRecord::Base

  belongs_to :students, class_name: 'Student'

end

class Student < ActiveRecord::Base

  belongs_to :classrooms, class_name: 'Classroom'

end

 B.

class Student < ActiveRecord::Base

  has_many :classrooms, dependent: true

end

class Classroom < ActiveRecord::Base

  has_many :students, dependent: false

end

 C.

class Student < ActiveRecord::Base

  has_many :classrooms

end

class Classroom < ActiveRecord::Base

  belongs_to :student

end

 D.

class Classroom < ActiveRecord::Base

  has_many :students

end

class Student < ActiveRecord::Base

  belongs_to :classroom

end

1 Answer

0 votes
by
A Rails project has ActiveRecord classes defined for Classroom and Student. If instances of these classes are related so that students are assigned the ID of one particular classroom, which choice shows the correct associations to define?

 

Correct answer is :-

class Classroom < ActiveRecord::Base

  has_many :students

end

class Student < ActiveRecord::Base

  belongs_to :classroom

end

Related questions

0 votes
asked Aug 26, 2022 in Ruby by Robin
0 votes
asked Aug 26, 2022 in Ruby by Robin
...