<pre><code>entry.brandFeature.one()
</code></pre>

<p>Is correct, you'll access the asset field and execute the <code>one()</code> function in order to fetch the asset.</p>

<pre><code>entry.category.one()
</code></pre>

<p>Is correct too. You'll <strong>fetch</strong> the first category of your categories field</p>

<pre><code>entry.category.one().categoryImage
</code></pre>

<p>Will access the <code>categoryImage</code> asset field of your category.</p>

<p>But then you do</p>

<pre><code>categoryImage.getUrl()
</code></pre>

<p>So you try to get the url from the field value but you don't actually grab the asset that might be stored in the category.</p>

<pre><code>categoryImage.one().getUrl()
</code></pre>

<p>However - keep in mind there could be entries without a category. Then you'll receive an error as well. </p>

CC BY-SA 4.0
2018-06-02T14:58:46.097Z
2018-06-02T14:58:46.097Z
Robin Schambach
<p>I'm trying to make it so that if an entry image does not exist, then fall back to the category image that the entry belongs to. Right now this isn't working and is receiving an error.</p>

<pre><code>{% set feature = entry.brandFeature.one() %}
{% set featureUrl = feature ? feature.url : entry.category.one().categoryImage.getUrl() %}
&lt;div class="jumbotron category-jumbotron" style="background-image:url({{ featureUrl }})"&gt;
</code></pre>

<p>This is the error that craft is returning:</p>

<blockquote>
  <p>Calling unknown method: craft\elements\db\AssetQuery::getUrl()</p>
</blockquote>

<entries><assets><categories>
Falling back to Parent Category if no asset exists
# Falling back to Parent Category if no asset exists

(Asked by: username_0 on 2018-06-02)

I'm trying to make it so that if an entry image does not exist, then fall back to the category image that the entry belongs to. Right now this isn't working and is receiving an error.
{% set feature = entry.brandFeature.one() %}
{% set featureUrl = feature ? feature.url : entry.category.one().categoryImage.getUrl() %}


This is the error that craft is returning:

Calling unknown method: craft\elements\db\AssetQuery::getUrl()

**Tags:** entries, assets, categories


---

## 1 answers

### Answer by username_1 on 2018-06-02. Score: 2 | Accepted answer

entry.brandFeature.one()

Is correct, you'll access the asset field and execute the one() function in order to fetch the asset.
entry.category.one()

Is correct too. You'll fetch the first category of your categories field
entry.category.one().categoryImage

Will access the categoryImage asset field of your category.
But then you do
categoryImage.getUrl()

So you try to get the url from the field value but you don't actually grab the asset that might be stored in the category.
categoryImage.one().getUrl()

However - keep in mind there could be entries without a category. Then you'll receive an error as well.


---

