autosurgeon icon indicating copy to clipboard operation
autosurgeon copied to clipboard

Support for foreign keys

Open teohhanhui opened this issue 2 years ago • 7 comments

I'd like to be able to reconcile / hydrate a related object as a foreign key in the document.

Currently, I'm running into a roadblock in the API:

In Reconcile::reconcile I'd need to be able to access the doc, to be able to determine the ObjId for the related object, in order to call reconcile_prop for it.

For example:

fn reconcile<R: Reconciler>(&self, mut reconciler: R) -> Result<(), R::Error> {
    let mut m = reconciler.map()?;
    // ...
    let Found(related_key) = self.related.key() else {
        // ...
    };
    let related_key = related_key.to_string();
    m.put("related", related_key)?;
    // no access to `doc`, and need to get `related_obj_id` from `doc` as well
    reconcile_prop(&mut doc, related_obj_id, &*related_key, &self.related)?;
    // ...
    Ok(())
}

teohhanhui avatar Dec 04 '22 09:12 teohhanhui