ruby on rails - :dependent => :destroy does not work -


i read lot of stuff association (belongs_to, has_many ...) think missed point somewhere, , can't find right answer.

here's schema posts:

create_table "posts", force: true |t| t.string   "titre" t.text     "description" t.string   "hastag" t.string   "postimg" t.integer  "utilisateur_id" t.datetime "created_at" t.datetime "updated_at" end  add_index "posts", ["utilisateur_id"], name: "index_posts_on_utilisateur_id", using: :btree 

when create new post, send "utilisateur_id" way:

@post = post.new(post_params) current_user = session[:utilisateur_id] @post.utilisateur_id = current_user 

in rails console, when type

user = utilisateur.find(id) user.posts 

and rails console finds posts associated user, mean association worked?

in post model, wrote belongs_to :utilisateur, :dependent => :destroy , in utilisateur model, wrote has_many posts.

when destroy user, posts associated not destroyed, , don't understand why.

thanks!

has_many :posts, :dependent => :destroy 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -