vendredi 1 septembre 2017

Rails variable data is changing

I have two tables that has many to many association

students projects

connected through the table student_projects

student = Student.find(1)
old_projects = student.projects

#Now Iam calling function that will create projects
create_projects

student = Student.find(1)
new_projects = student.projects
newly_added_projects = new_projects - old_projects

Old projects were empty,new_projects weren't

I put the logger statement before creating and after line(new_projects = students.projects), then I can see the difference.

But when I put the logger statement only after line (newly_added_projects = new_projects - old_projects) inspecting old_projects, new_projects, newly_added_projects

then old_projects is equal to new_projects

Can someone help me in this

Aucun commentaire:

Enregistrer un commentaire