diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-16 17:30:29 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-16 18:01:37 +0100 |
commit | 65068b6835dd3dc70107621351d1e452a42e1aac (patch) | |
tree | 311d0a4a5569227212786b94d6516699eeba0dd8 /src/commands/db.rs | |
parent | 7096cbd11f7c54681750a8d66a7ad76cf3846722 (diff) |
Fix: Use Job::belongs_to(&submit)
This fixes a bug where all jobs were loaded, not only the ones for the
specific submit.
The bug is fixed by using the new Job::belongs_to() association helper
interface added via the Associations functionality of diesel.
Awesome!
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r-- | src/commands/db.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs index c3c8e58..ea9bb9a 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -228,13 +228,16 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { .transpose()? .map(|submit_uuid| { use crate::schema; + use diesel::BelongingToDsl; - schema::jobs::table.inner_join({ - schema::submits::table.on(schema::submits::uuid.eq(submit_uuid)) - }) - .inner_join(schema::endpoints::table) - .inner_join(schema::packages::table) - .load::<(models::Job, models::Submit, models::Endpoint, models::Package)>(&conn) + let submit = models::Submit::with_id(&conn, &submit_uuid)?; + + models::Job::belonging_to(&submit) + .inner_join(schema::submits::table) + .inner_join(schema::endpoints::table) + .inner_join(schema::packages::table) + .load::<(models::Job, models::Submit, models::Endpoint, models::Package)>(&conn) + .map_err(Error::from) }) .unwrap_or_else(|| { dsl::jobs @@ -242,6 +245,7 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { .inner_join(crate::schema::endpoints::table) .inner_join(crate::schema::packages::table) .load::<(models::Job, models::Submit, models::Endpoint, models::Package)>(&conn) + .map_err(Error::from) })?; let data = jobs.into_iter() |