ruby-kit
                                
                                 ruby-kit copied to clipboard
                                
                                    ruby-kit copied to clipboard
                            
                            
                            
                        FetchLinks demo can't work
Hello,
I'm trying to have this example working on my project : https://prismic.io/docs/ruby/query-the-api/fetch-linked-document-fields
I have 2 custom types : "etude" and "auteur"
- "etude" has a linkedDocument to "auteur" named "auteur"
- "auteur" has several properties but I'm trying at least to get "nom" (StructuredText)
So when I try to get the study, it works :
study = Prismic.api('https://****.prismic.io/api').query(Prismic::Predicates.at('document.type', 'etude')}).results[0]
Then I added the fetchlink :
study = Prismic.api('https://****.prismic.io/api').query(Prismic::Predicates.at('document.type', 'etude'), {'fetchLinks' => 'auteur.nom'}).results[0]
I got an error pointing this line : undefined method "call' for nil:NilClass"
I tried to simply put "auteur" or "etude.auteur" and the error disapeared, but I'm unable to get the linked "auteur" as a top-level document. I tried those syntaxes, I always get an empty array or null :
- author = study["etude.auteur-link"]--> null
- author = study["etude.auteur"]--> []
- author = study["auteur.nom"]--> null
I can't have it work. Do you have any idea ?
Thanks
Update
I can confirm this bug still seems to exist when attempting to retrieve multiple fields from a linked document. Everything works when retrieving a single value, as per the example in the docs:
document = api.query(
    Prismic::Predicates.at("my.recipe.uid", "chocolate-chip-cookies"),
    { "fetchLinks" => "author.name" }
).results[0]
However, when following the documentation for fetching multiple fields from a linked document, I'm seeing the same undefined method 'call' for nil:NilClass error outlined above. It seems "fetchLinks" does not accept a list of attributes as suggested in the docs.
Question
- What is the accepted way to fetch multiple fields?
Current workaround
At the moment I'm having to run a separate query to fetch the author directly
@doc = api.getByUID('article', params[:uid], {
    "fetchLinks" => "author.full_name"
})
author_id = @doc["#{@doc.type}.author"].id
@author = api.getByID(author_id) if !author_id.nil?
I have the same issue, but in my instance I'm unable to use even one "fetchLinks" item.