4

I I would like plugins to be able to add properties to my models. For example, I have a model "Message". A "Like" plugin can add property "likedtimes" to it and maintain it. How can I get such functionality?

One solution is to create a separate table and model for likes. But that would require a join or additional select whenever likes are to be displayed.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156

1 Answers1

3

Are you trying to replicate common functionality between Entities (not models)?

If so, I would recommend you implement your own behavior, using the built-in event system.

FYI: Difference between entities and models

Community
  • 1
  • 1
Cobby
  • 5,273
  • 4
  • 28
  • 41
  • I am trying to allow third-party programmer to write plugins for my web application. I need to provide him a way to add properties to my entities. – Vladislav Rastrusny Jan 28 '11 at 07:12
  • 1
    I've looked into this before when I was trying to make my own behavior system. I couldn't bake in a way to dynamically add a column. You can't just modify the ClassMetadata because the entity physically needs the property. – Cobby Jan 29 '11 at 03:33
  • 1
    If you're interested, the best alternative I found was an EventListener that checked interfaces that the entity implemented and made sure the entity had certain properties based on that interface; if it didn't an exception was thrown. – Cobby Jan 31 '11 at 03:49