Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags with different categories #11

Open
nirvana-msu opened this issue Jan 27, 2015 · 5 comments
Open

Tags with different categories #11

nirvana-msu opened this issue Jan 27, 2015 · 5 comments
Assignees

Comments

@nirvana-msu
Copy link

Such taggable behaviors are a convenient way to store information for attributes that can take an array of values. And sometimes it is convenient to store information about different attributes in the same table using a special column to distinguish, say, category. What would be very useful if this extension allowed to work (save, load, search etc) with multiple tag categories defined for the same model.

This functionality was available in Yii1 through taggable extension by @samdark and was very useful.

You could potentially build on top of existing approach by attaching multiple TaggableBehavior behaviors, one per tag category, and adding a specific where clause like ->where('category = :category', [':category' => $category]); to each relation. But it has certain problems:

  • TaggableQueryBehavior right now does not distinguish between owner's behaviors and uses $model->tagRelation which would reference a relation from the first bahavior it finds instead of the one we need.
  • When saving tags, would be nice if tag category was saved automatically. This was handled by insertValues property in Yii1 taggable extension.
  • Yii1 taggable extension also provided useful methods like getAllTagsWithModelsCount, but this is less critical.
@creocoder
Copy link
Owner

It can be done without any additions to current behavior code and attaching multiple behaviors. I'll show how inside Advanced Usage section of documentation.

@creocoder creocoder self-assigned this Jan 27, 2015
@creocoder
Copy link
Owner

TaggableQueryBehavior right now does not distinguish between owner's behaviors and uses $model->tagRelation which would reference a relation from the first bahavior it finds instead of the one we need.

This drawback will be fixed. Thanks for catching.

@creocoder
Copy link
Owner

Yii1 taggable extension also provided useful methods like getAllTagsWithModelsCount, but this is less critical.

There is frequency attribute for that. But i'll consider implement method if it setted to false.

@nirvana-msu
Copy link
Author

I'll show how inside Advanced Usage section of documentation.

Looking forward to that! Will it also address the second issue (automatically saving category value)?

@nirvana-msu
Copy link
Author

There is frequency attribute for that. But i'll consider implement method if it setted to false.

Yes, this attribute is very useful. I don't think it worth implementing such method if for some reason user does not want to keep this field in the database.

What I meant is that in Yii1 getting this data was as simple as: $model->behaviorName->getAllTagsWithModelsCount(). Extension took care of filtering by category in where clause.

With this extension it seems like we would need to do something like Tag::find()->where('category = :category', [':category' => $category]). It would just be a bit more convenient if it somehow took care of adding this where clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants