<p>When targeting relational fields in URL formats, you should make sure to <a href="https://craftcms.com/docs/4.x/dev/functions.html#clone" rel="nofollow noreferrer"><code>clone()</code></a> the queries before calling params (to start &quot;fresh&quot; for each query, without any previously set params). Otherwise, query results could be unpredictable.</p>
<p>This should work:</p>
<pre><code>{slug}-{clone(restaurant).one().slug}-{clone(locations).inReverse().one().slug}-{clone(locations).one().slug}
</code></pre>

CC BY-SA 4.0
2022-06-13T08:36:53.283Z
That's a good hint. Thanks.
Mark H.
CC BY-SA 4.0
2022-06-13T08:19:05.277Z
2022-06-13T08:19:05.277Z
Mats Mikkel Rummelhoff
<p>Ok, after playing around there are 2 approaches that work.</p>
<p>Considering that category group is 2 level deep (state and city).</p>
<p>Done with levels:</p>
<pre><code>{slug}-{restaurant.one().slug}-{locations.level(2).one().slug}-{locations.level(1).one().slug}
</code></pre>
<p>Done with URI (category group format is city-state)</p>
<pre><code>{slug}-{restaurant.one().slug}-{locations.inReverse().one().uri}
</code></pre>

CC BY-SA 4.0
2022-06-13T08:03:20.353Z
2022-06-13T08:03:20.353Z
Mark H.
<p>I'm using the following URI format of a channel</p>

<pre><code>{slug}-{restaurant.one().slug}-{locations.last().slug}-{locations.one().slug}
</code></pre>

<p>It throws a deprecation error caused by <code>locations.last()</code></p>

<p>however when I use</p>

<pre><code>inReverse().one()
</code></pre>

<p>instead, it doesn't work as expected.</p>

<p>final syntax </p>

<pre><code>{slug}-{restaurant.one().slug}-{locations.inReverse().one().slug}-{locations.one().slug}
</code></pre>

CC BY-SA 4.0
2022-06-13T07:39:54.297Z
Bump. This tag was working despite the depreciation error - {locations.last().slug}, however it has stopped since the recent upgrade to craft v4. I assume .last() was depreciated competely. inReverse().one() does not work if using in the URL structure.
Mark H.
<url><uri>
Section URI format deprecation error
# Section URI format deprecation error

(Asked by: username_0 on 2019-08-01)

I'm using the following URI format of a channel
{slug}-{restaurant.one().slug}-{locations.last().slug}-{locations.one().slug}

It throws a deprecation error caused by locations.last()
however when I use
inReverse().one()

instead, it doesn't work as expected.
final syntax 
{slug}-{restaurant.one().slug}-{locations.inReverse().one().slug}-{locations.one().slug}

**Tags:** url, uri
> **Comments:**
> **username_0**: Bump. This tag was working despite the depreciation error - {locations.last().slug}, however it has stopped since the recent upgrade to craft v4. I assume .last() was depreciated competely. inReverse().one() does not work if using in the URL structure.  

---

## 2 answers

### Answer by username_1 on 2022-06-13. Score: 1 | Accepted answer

When targeting relational fields in URL formats, you should make sure to clone() the queries before calling params (to start "fresh" for each query, without any previously set params). Otherwise, query results could be unpredictable.
This should work:
{slug}-{clone(restaurant).one().slug}-{clone(locations).inReverse().one().slug}-{clone(locations).one().slug}

> **Comments:**
> **username_0**: That's a good hint. Thanks.  

---

### Answer by username_0 on 2022-06-13. Score: 0

Ok, after playing around there are 2 approaches that work.
Considering that category group is 2 level deep (state and city).
Done with levels:
{slug}-{restaurant.one().slug}-{locations.level(2).one().slug}-{locations.level(1).one().slug}

Done with URI (category group format is city-state)
{slug}-{restaurant.one().slug}-{locations.inReverse().one().uri}


---

