diff --git a/src/models/mod.rs b/src/models/mod.rs index 13edc569..fa4a4c82 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -12,6 +12,18 @@ macro_rules! find_by { }; } +macro_rules! list_by { + ($table:ident, $fn:ident, $($col:ident as $type:ident),+) => { + /// Try to find a $table with a given $col + pub fn $fn(conn: &PgConnection, $($col: $type),+) -> Vec { + $table::table + $(.filter($table::$col.eq($col)))+ + .load::(conn) + .expect("Error loading $table by $col") + } + }; +} + macro_rules! get { ($table:ident) => { pub fn get(conn: &PgConnection, id: i32) -> Option {