ruby on rails - Destroy doesn't destroy -


i've 3 models user formation & achat(let's translate sort of billing).

a user cand buy formation, create achat. reasons need delete 1 achat. didn't succeed. tried following work-flow check code:

irb(main):048:0> u.achats.length => 1 irb(main):049:0> u.achats.first.destroy!    (0.1ms)  begin    (0.1ms)  commit => #<achat id: 8, formation_id: 14, created_at: "2015-06-29 16:08:39", nom_formation: "foo", prix: 0.0, quantite: 1, chapitre_id: nil, user_id: 10, taux_commission: 35, updated_at: "2015-06-29 16:08:39", numero_facture: nil, bon_reduction_id: nil> irb(main):050:0> u.achats.length => 1 

so isn't deleted database. how should destroy achat?


here (simpler) version of models:

# coding: utf-8 class user < activerecord::base   rolify :role_cname => 'role'   # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable    #tous les achats de cette utilisateur   has_many :achats   #toutes les formations achetés par cet utilisateur   has_many :formations, :through => :achats end   #classe liant une formation à un utilisateur class achat < activerecord::base    #lien vers l'utilisateur qui acheté cette formation   belongs_to :user   #appartient à la classe formation   belongs_to :formation  end  #classe récupérant les différentes informations liées à toutes les formations présentes pour le site class formation < activerecord::base    #auteur de cette formation   belongs_to :user    # gestion de la relation pour l'achat   has_many :achats    #si la formation est publique alors on ne fait que changer le statut et la date de suppression   #si la formation n'a jamais été publié, alors on la supprime totalement de la base   def destroy     #si la formation est déja supprimée on bloque la chose     if(self.status.id == 3)       return formation_deja_supprime     else       update_attribute(:status, status.find(2))     end   end    # gestion de la suppression d'un produit   def delete!     update_attribute(:datesuppression, time.now)   end end 

i've been through question: dependent: :destroy doesn't work (has_many association) didn't helped...

record variable still available destroyed. try

achat.find(8) # or destroyed id 

to make sure have deleted record database

p.s. consider destroyed? method of rails understanding


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -