Delete cascade ? |
Hello,
I have an article table and a comment table. I hope that the comments of the article also disappear, how to do? Thank you in advance
(06-12-2017, 04:42 AM)tonny16 Wrote: Hello, PHP Code: $data = array( i prefer the soft delete. After x-months you can delete the rows. If you use foreign keys you only need to delete the article (on delete cascade) http://www.mysqltutorial.org/mysql-foreign-key/ if not: delete first the comments then the article PHP Code: $this->db->where('article_id', $article_id);
Thank you for your answers.
In mySQL I put this code: PHP Code: ALTER TABLE blog_commentaires How to put it in Codeigniter? Thank you in advance
In CI you can run any SQL statement with the query function
$this->db->query(" ALTER TABLE blog_commentaires ADD CONSTRAINT fk_comments_article FOREIGN KEY (id_article) REFERENCES article(id) ON DELETE CASCADE; ");
On the package it said needs Windows 7 or better. So I installed Linux.
Its all in the manual and much quicker to find then waiting for a reply in the forum
https://www.codeigniter.com/user_guide/d...mples.html
On the package it said needs Windows 7 or better. So I installed Linux.
(06-15-2017, 08:27 AM)rtenny Wrote: Its all in the manual and much quicker to find then waiting for a reply in the forum Thanks for all, I used an other solution PHP Code: $this->db->select('*'); |
Welcome Guest, Not a member yet? Register Sign In |