[][src]Function hdk::api::link_entries

pub fn link_entries<S: Into<String>>(
    base: &Address,
    target: &Address,
    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

#[derive(Serialize, Deserialize, Debug, DefaultJson)]
pub struct Post {
    content: String,
    date_created: String,
}

pub fn handle_link_entries(content: String, in_reply_to: Option<Address>) -> ZomeApiResult<Address> {

    let post_entry = Entry::App("post".into(), Post{
            content,
            date_created: "now".into(),
    }.into());

    let address = hdk::commit_entry(&post_entry)?;

    hdk::link_entries(
        &AGENT_ADDRESS,
        &address,
        "authored_posts",
    )?;

    if let Some(in_reply_to_address) = in_reply_to {
        // return with Err if in_reply_to_address points to missing entry
        hdk::get_entry_result(&in_reply_to_address, GetEntryOptions { status_request: StatusRequestKind::All, entry: false, headers: false, timeout: Default::default() })?;
        hdk::link_entries(&in_reply_to_address, &address, "comments")?;
    }

    Ok(address)

}