@@ -54,11 +54,9 @@ use diagnostic_shim::*;
5454/// Implements `AsChangeset`
5555///
5656/// To implement `AsChangeset` this derive needs to know the corresponding table
57- /// type. By default it uses the `snake_case` type name with an added `s`.
57+ /// type. By default it uses the `snake_case` type name with an added `s` from
58+ /// the current scope.
5859/// It is possible to change this default by using `#[table_name = "something"]`.
59- /// In both cases the module for that table must be in scope.
60- /// For example, to derive this for a struct called `User`, you will
61- /// likely need a line such as `use schema::users;`
6260///
6361/// If a field name of your struct differs
6462/// from the name of the corresponding column, you can annotate the field with
@@ -77,10 +75,10 @@ use diagnostic_shim::*;
7775/// the derive should threat `None` values as `NULL`. By default
7876/// `Option::<T>::None` is just skipped. To insert a `NULL` using default
7977/// behavior use `Option::<Option<T>>::Some(None)`
80- /// * `#[table_name = "some_table "]`, specifies the table for which the
81- /// current type is a changeset. Requires that `some_table` is in scope .
78+ /// * `#[table_name = "path::to::table "]`, specifies a path to the table for which the
79+ /// current type is a changeset. The path is relative to the current module .
8280/// If this attribute is not used, the type name converted to
83- /// `snake_case` with an added `s` is used as table name
81+ /// `snake_case` with an added `s` is used as table name.
8482///
8583/// ## Optional field attributes
8684///
@@ -148,15 +146,15 @@ pub fn derive_as_expression(input: TokenStream) -> TokenStream {
148146///
149147/// # Optional container attributes
150148///
151- /// * `#[table_name = "some_table_name "]` specifies the table this
152- /// type belongs to. Requires that `some_table_name` is in scope .
149+ /// * `#[table_name = "path::to::table "]` specifies a path to the table this
150+ /// type belongs to. The path is relative to the current module .
153151/// If this attribute is not used, the type name converted to
154- /// `snake_case` with an added `s` is used as table name
152+ /// `snake_case` with an added `s` is used as table name.
155153///
156154/// # Optional field attributes
157155///
158- /// * `#[column_name = "some_table_name "]`, overrides the column the current
159- /// field maps to to `some_table_name `. By default the field name is used
156+ /// * `#[column_name = "some_column_name "]`, overrides the column the current
157+ /// field maps to to `some_column_name `. By default the field name is used
160158/// as column name. Only useful for the foreign key field.
161159///
162160#[ proc_macro_derive( Associations , attributes( belongs_to, column_name, table_name) ) ]
@@ -187,25 +185,21 @@ pub fn derive_from_sql_row(input: TokenStream) -> TokenStream {
187185/// If it's not, you can put `#[primary_key(your_id)]` on your struct.
188186/// If you have a composite primary key, the syntax is `#[primary_key(id1, id2)]`.
189187///
190- /// By default, `#[derive(Identifiable)]` will assume that your table
191- /// name is the plural form of your struct name.
188+ /// By default, `#[derive(Identifiable)]` will assume that your table is
189+ /// in scope and its name is the plural form of your struct name.
192190/// Diesel uses very simple pluralization rules.
193191/// It only adds an `s` to the end, and converts `CamelCase` to `snake_case`.
194- /// If your table name does not follow this convention
195- /// or the plural form isn't just an `s`,
196- /// you can specify the table name with `#[table_name = "some_table_name"]`.
197- /// In both cases the module for that table must be in scope.
198- /// For example, to derive this for a struct called `User`, you will
199- /// likely need a line such as `use schema::users;`
192+ /// If your table name does not follow this convention or is not in scope,
193+ /// you can specify a path to the table with `#[table_name = "path::to::table"]`.
200194/// Our rules for inferring table names is considered public API.
201195/// It will never change without a major version bump.
202196///
203197/// # Attributes
204198///
205199/// ## Optional container attributes
206200///
207- /// * `#[table_name = "some_table_name "]` specifies the table this
208- /// type belongs to. Requires that `some_table_name` is in scope .
201+ /// * `#[table_name = "path::to::table "]` specifies a path to the table this
202+ /// type belongs to. The path is relative to the current module .
209203/// If this attribute is not used, the type name converted to
210204/// `snake_case` with an added `s` is used as table name
211205/// * `#[primary_key(id1, id2)]` to specify the struct field that
@@ -219,11 +213,9 @@ pub fn derive_identifiable(input: TokenStream) -> TokenStream {
219213/// Implements `Insertable`
220214///
221215/// To implement `Insertable` this derive needs to know the corresponding table
222- /// type. By default it uses the `snake_case` type name with an added `s`.
216+ /// type. By default it uses the `snake_case` type name with an added `s`
217+ /// from the current scope.
223218/// It is possible to change this default by using `#[table_name = "something"]`.
224- /// In both cases the module for that table must be in scope.
225- /// For example, to derive this for a struct called `User`, you will
226- /// likely need a line such as `use schema::users;`
227219///
228220/// If a field name of your
229221/// struct differs from the name of the corresponding column,
@@ -250,15 +242,15 @@ pub fn derive_identifiable(input: TokenStream) -> TokenStream {
250242///
251243/// ## Optional container attributes
252244///
253- /// * `#[table_name = "some_table_name "]`, specifies the table this type
254- /// is insertable into. Requires that `some_table_name` is in scope .
245+ /// * `#[table_name = "path::to::table "]`, specifies a path to the table this type
246+ /// is insertable into. The path is relative to the current module .
255247/// If this attribute is not used, the type name converted to
256248/// `snake_case` with an added `s` is used as table name
257249///
258250/// ## Optional field attributes
259251///
260- /// * `#[column_name = "some_table_name "]`, overrides the column the current
261- /// field maps to `some_table_name `. By default the field name is used
252+ /// * `#[column_name = "some_column_name "]`, overrides the column the current
253+ /// field maps to `some_column_name `. By default the field name is used
262254/// as column name
263255/// * `#[diesel(embed)]`, specifies that the current field maps not only
264256/// to single database field, but is a struct that implements `Insertable`
@@ -560,10 +552,6 @@ pub fn derive_queryable(input: TokenStream) -> TokenStream {
560552/// `diesel::dsl::SqlTypeOf<table_name::column_name>`), or by annotating each
561553/// field with `#[sql_type = "SomeType"]`.
562554///
563- /// If you are using `#[table_name]`, the module for that table must be in
564- /// scope. For example, to derive this for a struct called `User`, you will
565- /// likely need a line such as `use schema::users;`
566- ///
567555/// If the name of a field on your struct is different than the column in your
568556/// `table!` declaration, or if you are deriving this trait on a tuple struct,
569557/// you can annotate the field with `#[column_name = "some_column"]`. For tuple
@@ -585,9 +573,10 @@ pub fn derive_queryable(input: TokenStream) -> TokenStream {
585573///
586574/// ## Type attributes
587575///
588- /// * `#[table_name = "some_table"]`, to specify that this type contains
589- /// columns for the specified table. If no field attributes are specified
590- /// the derive will use the sql type of the corresponding column.
576+ /// * `#[table_name = "path::to::table"]`, to specify that this type contains
577+ /// columns for the specified table. The path is relative to the current module.
578+ /// If no field attributes are specified the derive will use the sql type of
579+ /// the corresponding column.
591580///
592581/// ## Field attributes
593582///
0 commit comments