-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Hi
This code used to work in beta20. I doesn't work as of RC6.
class CourseGroup
include Mongoid::Document
field :name
referenced_in :school
references_and_referenced_in_many :courses
accepts_nested_attributes_for :courses, :reject_if => lambda
, :allow_destroy => true
end
#In the Controller:
def create
@course_group = CourseGroup.new(params[:course_group])
@course_group.courses.each do |course|
course.school = @current_school
end
@current_school.course_groups << @course_group
if @course_group.save
redirect_to course_groups_path, :notice =>"Curso creado", :subdomain => @current_school.id
else
render 'new'
end
end
- End controller
class Course
include Mongoid::Document
field :name
referenced_in :school
references_and_referenced_in_many :course_groups
references_and_referenced_in_many :professors
end
encoding : utf-8
class School
include Mongoid::Document
include Mongoid::DynamicFinders
field :name
key :name
references_many :students
references_many :professors
references_many :courses
references_many :course_groups
referenced_in :user
validates :name, :presence => true
end
This is a Course_group saved in the database. It has courses, but those courses do not really exist. They aren't saved in the database.
{ "_id" : ObjectId("4d39b518511ea7043d00000b"), "course_ids" : [ ObjectId("4d39b518511ea7043d00000c"), ObjectId("4d39b518511ea7043d00000d"), ObjectId("4d39b518511ea7043d00000e") ], "name" : "WEEE", "school_id" : "pablo-de-olavide" }This used to work in beta.20