/*
Fetch data for a relationship and return a reference to it.

If the data was previously fetched (the 'Fetched' field is true), 'Save'
returns immediately.
*/
Fetch data for a relationship and return a reference to it.

If the data was previously fetched (the 'Fetched' field is true), 'Save'
returns immediately.
/ * Fetch data for a relationship and return a reference to it . If the data was previously fetched ( the ' Fetched ' field is true ) ' Save ' returns immediately . * /
func (r *Resource) Fetch(key string) (*Relationship, error) {
	relationship, exists := r.Relationships[key]
	if !exists {
		return nil, fmt.Errorf("relationship %s does not exist", key)
	}
	if relationship.Type == NULL {
		return nil, fmt.Errorf("cannot fetch null relationship")
	}
	if relationship.Fetched {
		return relationship, nil
	}
	if relationship.Type == SINGULAR {
		var url string
		if relationship.Links.Related != "" {
			url = relationship.Links.Related
		} else {
			url = fmt.Sprintf("/%s/%s",
				relationship.DataSingular.Type,
				relationship.DataSingular.Id)
		}
		Data, err := r.API.getFromPath(url)
		if err != nil {
			return relationship, err
		}
		relationship.Fetched = true
		relationship.DataSingular = &Data
	} else if relationship.Type == PLURAL {
		Url := relationship.Links.Related
		if Url == "" {
			return relationship, errors.New(
				"plural relationship doesn't have a 'related' link",
			)
		}
		Data, err := r.API.listFromPath(Url)
		if err != nil {
			return relationship, err
		}
		relationship.Fetched = true
		relationship.DataPlural = Data
	}
	return relationship, nil
}
func ( r * Resource ) Fetch ( key string ) ( * Relationship , error ) { relationship , exists := r . Relationships [ key ] if ! exists { return nil , fmt . Errorf ( " " , key ) } if relationship . Type == NULL { return nil , fmt . Errorf ( " " ) } if relationship . Fetched { return relationship , nil } if relationship . Type == SINGULAR { var url string if relationship . Links . Related != " " { url = relationship . Links . Related } else { url = fmt . Sprintf ( " " , relationship . DataSingular . Type , relationship . DataSingular . Id ) } Data , err := r . API . getFromPath ( url ) if err != nil { return relationship , err } relationship . Fetched = true relationship . DataSingular = & Data } else if relationship . Type == PLURAL { Url := relationship . Links . Related if Url == " " { return relationship , errors . New ( " " , ) } Data , err := r . API . listFromPath ( Url ) if err != nil { return relationship , err } relationship . Fetched = true relationship . DataPlural = Data } return relationship , nil }
Fetch data for a relationship and return a reference to it.
Fetch data for a relationship and return a reference to it .
// Now lets actually fetch