samdark / yii2-cookbook

Yii 2.0 Community Cookbook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Single table inheritance.

SamMousa opened this issue · comments

commented

Regarding: https://github.com/samdark/yii2-cookbook/blob/master/book/ar-single-table-inheritance.md

I have a package that simplifies STI and adds some more features that you don't get when using the method described codebook. It is located here: https://github.com/SAM-IT/yii2-magic

Some benefits:

  1. Uses configuration in a single place (the base class).
  2. Supports search models (ie classes that extend from subclasses of the base class).
  3. Implemented using traits so easy to combine with custom ActiveRecord and / or ActiveQuery implementations.

I'd split that repo into separate packages in the first place...

I still think that recipe is valid because it shows how to hack on AR.

commented

I don't doubt the validity of the recipe ^^.

For now I prefer to maintain it as a single collection; if at some point more people start using it and bugs are getting reported / PRs made I'll refactor it to use a meta-package and separate packages.

Just wanted to mention it here so people using the cookbook could find the package.

So any things in the recipe itself which are wrong? If yes, would be great to fix these...

commented

It requires changes in every subclass. So it's not wrong, but not (imo) the cleanest.
Feel free to close this if you're happy with how it is though :)

I think it's OK. Properties could be extracted from it if there are many such classes which usually isn't the case.