Error saving rails data

0

I mention my problem, when generating records using a callback (I already tried passing them directly but it does not work either) I always create the record with an id following this one.

association: has_many :modelo_hijo

self.modelo_hijo.destroy_all #elimino todas las referencias
unless self.modelo_hijo.nil? #valido que tenga ids
  self.modelo_hijo.each do |id| 
    self.modelo_hijo.create(person_id: id) #creo el incidente
  end
end

Let's say that the id of the parent model is 1 but always when calling self.modelo_hijo.create(person_id: id) it adds the id of the parent as 2 and the transaction is blocked.

the db is mysql, rails 5.0.2 and ruby 2.2.6p396

    
asked by mariovzc 06.06.2018 в 23:24
source

0 answers