xerions/ecto_taggable

Name: ecto_taggable

Owner: xerions

Description: Ecto taggable plugin

Created: 2015-04-13 10:48:55.0

Updated: 2018-04-20 17:13:53.0

Pushed: 2015-09-28 11:33:00.0

Homepage: null

Size: 168

Language: Elixir

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

EctoTaggable

ecto_taggable allows to tag any row of an ecto model.

For example you have model:

odule MyModel do
e Ecto.Model
hema "user" do
field :name, :string
field :old,  :integer
has_many :tags, {"test_model_tags", Ecto.Taggable}, [foreign_key: :tag_id] # foreign_key: tag_id is necessarily
d

You can migrate this model and related tags model to the database with ecto_migrate:

.Migration.Auto.migrate(EctoIt.Repo, MyModel)
.Migration.Auto.migrate(EctoIt.Repo, Ecto.Taggable, [for: MyModel])

Insert data in the database and set tag on this data:

odel1 = repo.insert(%MyModel{name: "foo", old: 20})
odel2 =repo.insert(%MyModel{name: "bar", old: 25})
.Taggable.set_tag(repo, my_model2 :tag_name)

ecto_taggable provides ability to search tag with:

.Taggable.search_tag(repo, MyModel, :tag_name) % ==> %MyModel{name: "bar", ...}

and delete tag for all recrods with:

.Taggable.Api.drop_tag(EctoIt.Repo, MyModel, :tag_name)

or for the certain id:

.Taggable.Api.drop_tag(EctoIt.Repo, %MyModel{id: 1}, :tag_name)

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.