0

I have two tables (just an example): Cars and Colors.

One Car have a Color, so I can't delete the color red if exists a car who is red. Easy.

With ZF1 I could verify easily this dependency before delete a color, by using findDependentRowset() method.

But how can I do this in ZF2?

It's a bad practice if I just let the delete method fail and than grab the exception and print a message?

Thanks!

4

1 に答える 1

1

findDependantRowset()ZF2にはもう直接の実装はありません。ZF2は、完全なORMを提供するステップに戻り、代わりに、クエリ管理を容易にする機能を提供しました。

そしてまさにこれがあなたのアプローチでしょう。Query for CAR次に、 2つのクエリを実行するかQuery Colords for CarColor、1つのクエリを実行して、両方を同時にクエリします。後者はより速いアプローチであり、最初のものはほとんど何をしたかfindDependantRowset()です。

より多くの「魔法」機能が必要な場合は、そこにある多くの優れたORMの1つを確認することをお勧めします。たとえば、Doctrine 2にはすでにかなりきちんとしたZF2実装があり、ZF2に関する限り、コミュニティ標準のようです。https://github.com/doctrine/DoctrineORMModuleをチェックアウトすることをお勧めします

于 2012-12-06T07:15:48.677 に答える