Db relations

Issue #225, please @mnzaki review and merge ASAP.