Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC Move orderBy docs to raw SQL section. #353

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Comment on lines -314 to -315
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question. Should we completely remove this statement or we could also move it in "Order by" section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this is incorrectly saying you need to use raw SQL to do a random sort, but that's what the shuffle() method is for.
The rest of this is saying that raw SQL is inherently risky, which is already stated in the raw SQL section.

Basically, I don't think there's anything here that we need to keep.


## 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