samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.45k stars 297 forks source link

Single table inheritance. #111

Closed SamMousa closed 8 years ago

SamMousa commented 8 years ago

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.
samdark commented 8 years ago

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

samdark commented 8 years ago

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

SamMousa commented 8 years ago

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.

samdark commented 8 years ago

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

SamMousa commented 8 years ago

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 :)

samdark commented 8 years ago

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