-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite
#[derive(Associations)]
in derives2
This was a pretty straightforward rewrite. Overall I feel much better about this code structure than what we had before. We're having to do a bit of funkyness to avoid rust-lang/rust#47941, but other than that everything here was pretty straightforward. I had the UI tests guide me the entire time.
- Loading branch information
Showing
19 changed files
with
397 additions
and
210 deletions.
There are no files selected for viewing
32 changes: 0 additions & 32 deletions
32
diesel_compile_tests/tests/compile-fail/associations_errors.rs
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[macro_use] | ||
extern crate diesel; | ||
|
||
table! { | ||
foo { | ||
id -> Integer, | ||
} | ||
} | ||
|
||
#[derive(Identifiable)] | ||
#[table_name = "foo"] | ||
struct Bar { | ||
id: i32, | ||
} | ||
|
||
#[derive(Identifiable)] | ||
#[table_name = "foo"] | ||
struct Baz { | ||
id: i32, | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to] | ||
#[belongs_to = "Bar"] | ||
#[belongs_to()] | ||
#[belongs_to(foreign_key = "bar_id")] | ||
#[belongs_to(Bar, foreign_key)] | ||
#[belongs_to(Bar, foreign_key(bar_id))] | ||
#[belongs_to(Baz, foreign_key = "bar_id", random_option)] | ||
struct Foo { | ||
bar_id: i32, | ||
} | ||
|
||
fn main() {} |
48 changes: 48 additions & 0 deletions
48
diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error: `belongs_to` must be in the form `belongs_to(...)` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to] | ||
| ^ | ||
|
||
error: `belongs_to` must be in the form `belongs_to(...)` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to = "Bar"] | ||
| ^ | ||
|
||
error: Expected a struct name | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to()] | ||
| ^ | ||
| | ||
= help: e.g. `#[belongs_to(User)]` | ||
|
||
error: Expected a struct name | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(foreign_key = "bar_id")] | ||
| ^ | ||
| | ||
= help: e.g. `#[belongs_to(User)]` | ||
|
||
error: `foreign_key` must be in the form `foreign_key = "value"` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key)] | ||
| ^ | ||
|
||
warning: The form `foreign_key(value)` is deprecated. Use `foreign_key = "value"` instead | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key(bar_id))] | ||
| ^ | ||
|
||
warning: Unrecognized option random_option | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Baz, foreign_key = "bar_id", random_option)] | ||
| ^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
42 changes: 42 additions & 0 deletions
42
diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#[macro_use] | ||
extern crate diesel; | ||
|
||
struct Bar; | ||
|
||
table! { | ||
foo { | ||
id -> Integer, | ||
} | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar)] | ||
#[table_name = "foo"] | ||
struct Foo1 { | ||
bar_id: i32, | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar, foreign_key = "bar_id")] | ||
#[table_name = "foo"] | ||
struct Foo2 { | ||
bar_id: i32, | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar)] | ||
#[table_name = "foo"] | ||
struct Foo3 { | ||
#[column_name = "bar_id"] | ||
baz_id: i32, | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar, foreign_key = "bar_id")] | ||
#[table_name = "foo"] | ||
struct Foo4 { | ||
#[column_name = "bar_id"] | ||
baz_id: i32, | ||
} | ||
|
||
fn main() {} |
50 changes: 50 additions & 0 deletions
50
diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_column.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error[E0412]: cannot find type `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ not found in `foo` | ||
|
||
error[E0425]: cannot find value `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ not found in `foo` | ||
|
||
error[E0412]: cannot find type `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ not found in `foo` | ||
|
||
error[E0425]: cannot find value `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ not found in `foo` | ||
|
||
error[E0412]: cannot find type `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ not found in `foo` | ||
|
||
error[E0425]: cannot find value `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ not found in `foo` | ||
|
||
error[E0412]: cannot find type `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ not found in `foo` | ||
|
||
error[E0425]: cannot find value `bar_id` in module `foo` | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ not found in `foo` | ||
|
||
error: aborting due to 8 previous errors | ||
|
19 changes: 19 additions & 0 deletions
19
diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[macro_use] | ||
extern crate diesel; | ||
|
||
struct Bar; | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar)] | ||
#[belongs_to(Bar, foreign_key = "bar_id")] | ||
struct Foo {} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar)] | ||
#[belongs_to(Bar, foreign_key = "bar_id")] | ||
struct Baz { | ||
#[column_name = "baz_id"] | ||
bar_id: i32, | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
diesel_compile_tests/tests/ui/belongs_to_missing_foreign_key_field.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: No field with column name bar_id | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ | ||
|
||
error: No field with column name bar_id | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ | ||
|
||
error: No field with column name bar_id | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ | ||
|
||
error: No field with column name bar_id | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar, foreign_key = "bar_id")] | ||
| ^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
17 changes: 17 additions & 0 deletions
17
diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[macro_use] | ||
extern crate diesel; | ||
|
||
table! { | ||
foos { | ||
id -> Integer, | ||
bar_id -> Integer, | ||
} | ||
} | ||
|
||
#[derive(Associations)] | ||
#[belongs_to(Bar)] | ||
struct Foo { | ||
bar_id: i32, | ||
} | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error[E0412]: cannot find type `Bar` in this scope | ||
--> <macro expansion>:1:1 | ||
| | ||
1 | #[belongs_to(Bar)] | ||
| ^ not found in this scope | ||
|
||
error: aborting due to previous error | ||
|
Oops, something went wrong.