How is a multi-link field stored within DatoCMS, is it an array of ids or strings?

Need some help with syntax

<% dato.articles.select{ |t| t.topic.include?(topic.title) }.sort_by(&:date_published).each do |article| %>

I am trying to loop through all the articles WHERE the article.topic includes the topic.title value passed to page via locals during a proxy build

So for example one of my topics is ‘CMS’ and i want to select(filter) all the articles using my DatoCMS middleman gem that have ‘CMS’ as one of their topics (they might also have ‘Web Design’ and ‘Web Advice’ as topics included in the link field) I am wondering firstly how the link field stores the ‘topics’ and furthermore if the Dato gem is able to filter them if indeed they are in an array?

Can anyone help
Dave

So at last I found out how to do what I needed. I’ll put it up here in case anyone else ever needs to filter a dataset using a multi-link field in DatoCMS with the dato middleman gem

<% dato.articles.select { | item | item.topic.find { |t| t.title == topic.title } }.sort_by(&:date_published).each do |article| %>

Also some useful debugging techniques to see the format of the data you are working with

<%= dato.articles.to_json %>
<%= topic.to_json %>
<% dato.articles.select { | item | item.topic.find { |t| t.title == topic.title } }.sort_by(&:date_published).to_json %>
	

and you can

<%= put dato.articles %>
into your terminal/console for example, it gives a more accurate picture of the data, IMHO

1 Like