Skip to content

Commit

Permalink
Merge pull request #353 from creative-commoners/pulls/5.1/update-orde…
Browse files Browse the repository at this point in the history
…rby-docs

DOC Move orderBy docs to raw SQL section.
  • Loading branch information
sabina-talipova authored Sep 28, 2023
2 parents 6f14784 + 3f66ce3 commit 61a916f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,12 @@ $players = Players::get()->sort([
]);
```

You can also sort randomly. Using the `DB` class, you can get the random sort method per database type.
You can also sort randomly.

```php
$random = DB::get_conn()->random();
$players = Player::get()->orderBy($random);
$players = Player::get()->shuffle();
```

[warning]
Note that we've used the `orderBy()` method here. This is because `sort()` doesn't allow sorting by raw SQL, which is necessary to use a random sort. Be careful whenever you use the `orderBy()` method to ensure you don't pass in any values you can't trust.
[/warning]

## Filtering Results

The `filter()` method filters the list of objects that gets returned.
Expand Down Expand Up @@ -657,6 +652,14 @@ You can specify a WHERE clause fragment (that will be combined with other filter
$members = Member::get()->where("\"FirstName\" = 'Sam'");
```

#### Order by clauses

You can specify an ORDER BY clause fragment with the `orderBy` method:

```php
$members = Member::get()->orderBy(/* some raw SQL here */);
```

#### Joining Tables

You can specify a join with the `innerJoin` and `leftJoin` methods. Both of these methods have the same arguments:
Expand Down

0 comments on commit 61a916f

Please sign in to comment.