---
title: "استخدام scope مع or في Rails"
description: "scope :human, -> { user.or(author) } scope :terminator, -> { admin.or(robot) } `"
canonical: https://oozou.com/til/scope-or-scope-in-rails-11
locale: ar
date: 2020-10-13
topic: ruby-on-rails
---

# استخدام scope مع or في Rails

> scope :human, -> { user.or(author) } scope :terminator, -> { admin.or(robot) } `

Published: 2020-10-13 · Topic: [ruby on rails](https://oozou.com/ar/til-topics/ruby-on-rails) ([markdown](https://oozou.com/ar/til-topics/ruby-on-rails.md))

```ruby
# app/models/user.rb
...
enum role: { user: 0, author: 1, admin: 2, robot: 3 }

scope :human, -> { user.or(author) }
scope :terminator, -> { admin.or(robot) }
```

ينتج عنه

```ruby
User.human.to_sql
#=> "SELECT \"users\".* FROM \"users\" WHERE (\"users\".\"role\" = 0 OR \"users\".\"role\" = 1)"
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/ar/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
