1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Tags for any [SeaORM](https://www.sea-ql.org/SeaORM/) entity.
//!
//! One `tags` table serves every taggable entity through the polymorphic `taggables`
//! pivot. Mark an entity, and each of its rows gets a [`tags`](HasTags::tags) handle:
//!
//! ```no_run
//! # mod posts { use sea_orm::entity::prelude::*;
//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
//! # #[sea_orm(table_name = "posts")]
//! # pub struct Model { #[sea_orm(primary_key)] pub id: i32 }
//! # #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {}
//! # impl ActiveModelBehavior for ActiveModel {} }
//! use sea_orm::{DatabaseConnection, DbErr, EntityTrait, QueryFilter};
//! use sea_orm_taggable::{HasTags, Morphable, TagFilters, Taggable};
//!
//! impl Morphable for posts::Entity {
//! const MORPH_TYPE: &'static str = "post";
//! }
//! impl Taggable for posts::Entity {}
//!
//! async fn example(db: &DatabaseConnection, post: &posts::Model) -> Result<(), DbErr> {
//! post.tags().attach(db, ["Rust", "SeaORM"], None).await?;
//! post.tags().attach(db, ["Beginner"], Some("level")).await?;
//!
//! let about_rust = posts::Entity::find()
//! .filter(posts::Entity::with_any_tags(["rust"], None))
//! .all(db)
//! .await?;
//! Ok(())
//! }
//! ```
//!
//! - Tags are created from names on first use; a slug is made from the name, unique
//! within the tag's type.
//! - **Types** group tags (`"topic"`, `"level"`); `None` is the plain group.
//! - Each row keeps its tags in its own order; tags also have a global position within
//! their type ([`tag::Model::move_to_start`] and friends).
//! - Load the tags of a page of rows in two queries with [`load_tags`].
//!
//! The pivot cannot have a foreign key to the tagged rows, so call
//! [`Tags::detach_all`] in the row's delete hook (for soft-deleted rows, when they
//! are deleted for good), or [`delete_orphans`] from a scheduled task.
use ;
use ;
pub use TagFilters;
pub use ;
pub use ;
/// An entity whose rows can be tagged. Its [`Morphable::MORPH_TYPE`] is stored in
/// `taggables.taggable_type`, and its primary key must be an integer.
/// The polymorphic many-to-many relation behind the tags, for queries this crate
/// does not cover; see `sea-orm-relations-kit`.
pub const TAGS: = new
.ordered_by;
/// The tags of many rows, in two queries, each list in the row's own order.
///
/// # Errors
///
/// On a database error.
pub async
/// How many tags each row has, in one query.
///
/// # Errors
///
/// On a database error.
pub async
/// Removes the pivot rows of `O` rows that no longer exist. Returns how many went.
///
/// # Errors
///
/// On a database error.
pub async