Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/craftcms/cms into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG-v3.md
  • Loading branch information
andris-sevcenko committed Sep 17, 2019
2 parents dae6e85 + df7c7e9 commit 5c816dc
Show file tree
Hide file tree
Showing 30 changed files with 2,317 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

## Unreleased

### Changed
- Improved the button labels in the confirmation dialog that can appear after running the Asset Indexes utility. ([#4943](https://github.com/craftcms/cms/issues/4943))

### Fixed
- Fixed a bug where asset queries’ `withTransforms` param wasn’t working for eager-loaded assets. ([#4931](https://github.com/craftcms/cms/issues/4931))
- Fixed a bug where the "Edit Image" element action sometimes would be missing. ([#3349](https://github.com/craftcms/cms/issues/3349))
- Fixed a bug where querying for elements by their Lightswitch field value could only return elements that had been saved since the Lightswitch field was added. ([#4939](https://github.com/craftcms/cms/issues/4939))
- Fixed a bug where the "Update all" button was missing on the updates page. ([#4938](https://github.com/craftcms/cms/issues/4938))
- Fixed a bug where the “Updating search indexes” job could fail when updating search indexes for a Matrix block that contained a relational field.
- Fixed a bug where it was impossible to query for entries using author id with the GraphQL API.

## 3.3.3 - 2019-09-12
Expand Down
325 changes: 324 additions & 1 deletion docs/dev/element-queries/asset-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,128 @@ $assets = \craft\elements\Asset::find()
:::


### `draftCreator`

Narrows the query results to only drafts created by a given user.



Possible values include:

| Value | Fetches drafts…
| - | -
| `1` | created by the user with an ID of 1.
| a `\craft\elements\db\User` object | by the user represented by the object.



::: code
```twig
{# Fetch drafts by the current user #}
{% set assets = craft.assets()
.draftCreator(currentUser)
.all() %}
```

```php
// Fetch drafts by the current user
$assets = \craft\elements\Asset::find()
->draftCreator(Craft::$app->user->identity)
->all();
```
:::


### `draftId`

Narrows the query results based on the assets’ draft’s ID (from the `drafts` table).



Possible values include:

| Value | Fetches drafts…
| - | -
| `1` | for the draft with an ID of 1.



::: code
```twig
{# Fetch a draft #}
{% set assets = craft.assets()
.draftId(10)
.all() %}
```

```php
// Fetch a draft
$assets = \craft\elements\Asset::find()
->draftIf(10)
->all();
```
:::


### `draftOf`

Narrows the query results to only drafts of a given asset.



Possible values include:

| Value | Fetches drafts…
| - | -
| `1` | for the asset with an ID of 1.
| a [Asset](api:craft\elements\Asset) object | for the asset represented by the object.



::: code
```twig
{# Fetch drafts of the asset #}
{% set assets = craft.assets()
.draftOf(myAsset)
.all() %}
```

```php
// Fetch drafts of the asset
$assets = \craft\elements\Asset::find()
->draftOf($myAsset)
->all();
```
:::


### `drafts`

Narrows the query results to only drafts assets.





::: code
```twig
{# Fetch a draft asset #}
{% set assets = {twig-function}
.drafts()
.id(123)
.one() %}
```

```php
// Fetch a draft asset
$assets = \craft\elements\Asset::find()
->drafts()
->id(123)
->one();
```
:::


### `filename`

Narrows the query results based on the assets’ filenames.
Expand Down Expand Up @@ -383,6 +505,20 @@ This can be combined with [fixedOrder](#fixedorder) if you want the results to b
:::


### `ignorePlaceholders`

Causes the query to return matching assets as they are stored in the database, ignoring matching placeholder
elements that were set by [craft\services\Elements::setPlaceholderElement()](https://docs.craftcms.com/api/v3/craft-services-elements.html#method-setplaceholderelement).










### `inReverse`

Causes the query results to be returned in reverse order.
Expand Down Expand Up @@ -559,6 +695,41 @@ $assets = \craft\elements\Asset::find()
:::


### `preferSites`

If [unique](#unique) is set, this determines which site should be selected when querying multi-site elements.



For example, if element “Foo” exists in Site A and Site B, and element “Bar” exists in Site B and Site C,
and this is set to `['c', 'b', 'a']`, then Foo will be returned for Site C, and Bar will be returned
for Site B.

If this isn’t set, then preference goes to the current site.



::: code
```twig
{# Fetch unique assets from Site A, or Site B if they don’t exist in Site A #}
{% set assets = craft.assets()
.site('*')
.unique()
.preferSites(['a', 'b'])
.all() %}
```

```php
// Fetch unique assets from Site A, or Site B if they don’t exist in Site A
$assets = \craft\elements\Asset::find()
->site('*')
->unique()
->preferSites(['a', 'b'])
->all();
```
:::


### `relatedTo`

Narrows the query results to only assets that are related to certain other elements.
Expand Down Expand Up @@ -586,6 +757,128 @@ $assets = \craft\elements\Asset::find()
:::


### `revisionCreator`

Narrows the query results to only revisions created by a given user.



Possible values include:

| Value | Fetches revisions…
| - | -
| `1` | created by the user with an ID of 1.
| a `\craft\elements\db\User` object | by the user represented by the object.



::: code
```twig
{# Fetch revisions by the current user #}
{% set assets = craft.assets()
.revisionCreator(currentUser)
.all() %}
```

```php
// Fetch revisions by the current user
$assets = \craft\elements\Asset::find()
->revisionCreator(Craft::$app->user->identity)
->all();
```
:::


### `revisionId`

Narrows the query results based on the assets’ revision’s ID (from the `revisions` table).



Possible values include:

| Value | Fetches revisions…
| - | -
| `1` | for the revision with an ID of 1.



::: code
```twig
{# Fetch a revision #}
{% set assets = craft.assets()
.revisionId(10)
.all() %}
```

```php
// Fetch a revision
$assets = \craft\elements\Asset::find()
->revisionIf(10)
->all();
```
:::


### `revisionOf`

Narrows the query results to only revisions of a given asset.



Possible values include:

| Value | Fetches revisions…
| - | -
| `1` | for the asset with an ID of 1.
| a [Asset](api:craft\elements\Asset) object | for the asset represented by the object.



::: code
```twig
{# Fetch revisions of the asset #}
{% set assets = craft.assets()
.revisionOf(myAsset)
.all() %}
```

```php
// Fetch revisions of the asset
$assets = \craft\elements\Asset::find()
->revisionOf($myAsset)
->all();
```
:::


### `revisions`

Narrows the query results to only revision assets.





::: code
```twig
{# Fetch a revision asset #}
{% set assets = {twig-function}
.revisions()
.id(123)
.one() %}
```

```php
// Fetch a revision asset
$assets = \craft\elements\Asset::find()
->revisions()
->id(123)
->one();
```
:::


### `search`

Narrows the query results to only assets that match a search query.
Expand Down Expand Up @@ -639,7 +932,7 @@ Possible values include:

::: tip
If multiple sites are specified, elements that belong to multiple sites will be returned multiple times. If you
only want unique elements to be returned, use `\craft\elements\db\unique()` in conjunction with this.
only want unique elements to be returned, use [unique](#unique) in conjunction with this.
:::


Expand Down Expand Up @@ -806,6 +1099,36 @@ $asset = \craft\elements\Asset::find()
:::


### `unique`

Determines whether only elements with unique IDs should be returned by the query.



This should be used when querying elements from multiple sites at the same time, if “duplicate” results is not
desired.



::: code
```twig
{# Fetch unique assets across all sites #}
{% set assets = craft.assets()
.site('*')
.unique()
.all() %}
```

```php
// Fetch unique assets across all sites
$assets = \craft\elements\Asset::find()
->site('*')
->unique()
->all();
```
:::


### `volume`

Narrows the query results based on the volume the assets belong to.
Expand Down
Loading

0 comments on commit 5c816dc

Please sign in to comment.