开发者

What's the difference ElggMetadata and ElggAnnotation in Elgg framework from a developer viewpoint?

I can not understand th开发者_StackOverflow中文版e difference.


From a database perspective, they are exactly the same. They have all the same fields (id, user_guid, entity_guid, etc.), so it would make sense why it's not immediately clear what they're for.

I like to think of it this way:

  • metadata == objective (property)
  • annotations == subjective (opinion)

Metadata are a way to dynamically add properties to an entity. Metadata should describe the entity as it actually is -- David's example about the color of a car was good. Other examples are the isbn number of a book, or the location of an event.

Any new information added to the entity after it's been created should probably be an annotation. This is why ratings, likes, etc. are annotations and not metadata -- a "rating" is not a property of the entity, it's just someone's opinion about the quality of the entity.

The API bears this distinction out. Metadata are assigned as if they were properties of the entity. e.g.:

$event->location = '';

There is no equivalent shorthand for annotations.


ElggMetadata is used to store information about the actual Elgg entity. So if you created a Car entity and wanted to say what colour it was, that would be a perfect use case for ElggMetadata.

ElggAnnotion is used to add additional information (comment, review, etc.) to an entity. So in the above example of a Car Entity, you could allow users to comment or review it. This is a perfect case for ElggAnnotation.


ElggMetadata is where the LINK between key-value pairs are stored, associated with any entity. But the actual key and values will be stored in ElggMetastrings( following EAV model).

For example:

$user->gender=male; 

Comparatively ElggAnnotation stores quite a rigid set of properties like comments, ratings of any entity

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜