Is there a mean to specify a cascade deleting as it is done in Laravel ?
This is a Laravel5 code (what an expressive and clean code) in a migration file but i guess something exist in Yii2 to achieve same thing, but i can’t found it (ahhhh the Doc…)
Do you how to achieve this ?
Lets say you have "article" and "comments" and want cascade delete.
Then this should work when I’m not wrong.
public function up()
// CREATE TABLE: comment
'id' => Schema::TYPE_PK,
'article_id' => 'int(11) NOT NULL',
// ... other attributes ...
'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
), 'ENGINE=InnoDB DEFAULT CHARSET=utf8'
// ADD FOREIGN_KEY / CASCADE DELETE
// addForeignKey('describtion', 'thisTable', 'linkingField', 'targetTable', 'targetField, 'CASCADE', 'CASCADE');
// so for comment and user for example:
$this->addForeignKey('FK_comment_to_article', 'comment', 'article_id', 'article', 'id','CASCADE','CASCADE');
Hope this helps?
Yes it helps me a lot
But i am sad.
Because Laravel syntax is much more clear than the Yii2 one
Why are you using yii then?
When you like laravel more?
Or is someone forcing you to do so?
Things are more complicate.
Laravel syntax is much more convenient
Yii come with other advantages
But maybe beacuse we are on yii forum we have to say only good things about yii ?
thx for your help
Don’t get me wrong.
That was no offense.
Of course every framework has its pros and cons.
I was just wondering how it comes that you use yii when you are already familar with laravel.
(for example could be possible that a client forces you to use yii for weird reasons)
At the end the only thing that counts is that we get done what we need.
Anyway - I’m glad when the solution works.
Laravel has good solutions. I’m sad to say that it will become better than yii in One or Two years
I use it in a project. I use also Yii.
For instance both I great for some kind of projects.
It was not an offense but I hesitate too much for my next project which framework i will use…