Shopify / Shopify/liquid

I have strange behaviour of filter 'unique'

Open
#1,270 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I have the array in JSON format:

[
  {
      "id": 0,
      "type": "Type Zero",
      "date": "2020-02-22",
      "phone": 380001000000,
      "images":  ""
  },
  {
      "id": 1,
       "type": "Type One",
      "date": "2020-04-24",
      "phone": 380001000000,
      "images": ""
  },
  {
      "id": 2,
      "type": "Type Two",
      "date": "2020-07-08",
      "phone": 380002000000,
      "images": ""
  }
]

{%- assign model = site.data.models | map: "phone" | uniq -%}

I get: Liquid Exception: no implicit conversion of String into Integer in... hints at "phone", but is not problem i changed it to...

[
  {
      "id": 0,
      "type": "Type Zero",
      "date": "2020-02-22",
      "phone": "380001000000",
      "images":  ""
  },
  {
      "id": 1,
       "type": "Type One",
      "date": "2020-04-24",
      "phone": "380001000000",
      "images": ""
  },
  {
      "id": 2,
      "type": "Type Two",
      "date": "2020-07-08",
      "phone": "380002000000",
      "images": ""
  }
]

{%- assign model = site.data.models | map: "phone" | uniq -%}

<ul>
  {%- for too in model -%}
  <li>{{ too.id }} / {{ too.type }} / {{ too.data }} / {{ too.phone }} / {{ too.images }}</li>
  {%- endfor -%}
</ul>

....in the array model i expected get

[
  {
      "id": 0,
      "type": "Type Zero",
      "date": "2020-02-22",
      "phone": "380001000000",
      "images":  ""
  },
  {
      "id": 2,
      "type": "Type Two",
      "date": "2020-07-08",
      "phone": "380002000000",
      "images": ""
  }
]
<ul>
  <li> 0 / Type Zero / 2020-02-22 / 380001000000 / </li>
  <li> 1 / Type Two / 2020-07-08 / 380002000000 / </li>
</ul>

but in the array model i get nothing if exactly I see

Now I see only one field "phone" i do not understand where other fields...?

<ul>
  <li> / / / 380001000000 / </li>
  <li> / / / 380002000000 / </li>
</ul>

Why? Did I miss something?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Reproduce the supplied JSON and the map: "phone" | uniq template, then inspect the filter behavior and its documented output; done means the observed result and expected object shape are reconciled.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.