File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ /// ```
138pub 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}
You can’t perform that action at this time.
0 commit comments