Skip to content

Commit 6d2d0bf

Browse files
committed
Add docs to BelongingToDsl
1 parent 2ec3f2d commit 6d2d0bf

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1+
/// Constructs a query that finds record(s) based on directional association with other record(s).
2+
///
3+
/// # Example
4+
///
5+
/// ```rust
6+
/// # #[macro_use] extern crate diesel;
7+
/// # #[macro_use] extern crate diesel_codegen;
8+
/// # include!("../doctest_setup.rs");
9+
/// # use schema::{posts, users};
10+
/// #
11+
/// # #[derive(Identifiable, Queryable)]
12+
/// # pub struct User {
13+
/// # id: i32,
14+
/// # name: String,
15+
/// # }
16+
/// #
17+
/// # #[derive(Debug, PartialEq)]
18+
/// # #[derive(Identifiable, Queryable, Associations)]
19+
/// # #[belongs_to(User)]
20+
/// # pub struct Post {
21+
/// # id: i32,
22+
/// # user_id: i32,
23+
/// # title: String,
24+
/// # }
25+
/// #
26+
/// # fn main() {
27+
/// # let connection = establish_connection();
28+
/// # use users::dsl::*;
29+
/// # let user = users.find(2).get_result::<User>(&connection).unwrap();
30+
/// let posts = Post::belonging_to(&user)
31+
/// # .load::<Post>(&connection);
32+
/// #
33+
/// # assert_eq!(posts,
34+
/// # Ok(vec![Post { id: 3, user_id: 2, title: "My first post too".to_owned() }])
35+
/// # );
36+
/// # }
37+
/// ```
138
pub trait BelongingToDsl<T> {
39+
/// The query returned by `belonging_to`
240
type Output;
341

42+
/// Get the record(s) belonging to record(s) `other`
443
fn belonging_to(other: T) -> Self::Output;
544
}

0 commit comments

Comments
 (0)