[][src]Function hdk::link_entries

pub fn link_entries<S: Into<String>>(
    base: &HashString,
    target: &HashString,
    tag: S
) -> Result<(), ZomeApiError>

Consumes three values, two of which are the addresses of entries, and one of which is a string that defines a relationship between them, called a tag. Later, lists of entries can be looked up by using get_links. Entries can only be looked up in the direction from the base, which is the first argument, to the target.

Examples

pub fn handle_create_post(content: String) -> serde_json::Value {
    let maybe_address = hdk::commit_entry("post", json!({
        "content": content,
        "date_created": "now"
    }));
    match maybe_address {
        Ok(post_address) => {
            let link_result = hdk::link_entries(
                &HashString::from(AGENT_ADDRESS.to_string()),
                &post_address,
                "authored_posts"
            );
            if link_result.is_err() {
                return json!({"link error": link_result.err().unwrap()})
            }
            json!({"address": post_address})
        }
        Err(hdk_error) => hdk_error.to_json(),
    }
}