---
title: "scope in Rails4"
author: "南京老油条"
date: "2014-04-18T09:57:49Z"
tags: []
categories: ["编程语言"]
slug: "scope-in-rails4"
draft: false
lastmod: "2014-04-18T09:57:49Z"
id: 2048145
url: "https://oldfritter.iteye.com/blog/2048145"
---

Rails4 中scope推荐写法,代替原先的lambda

 

```
 scope :all_by_shop, ->(store_id) {where("(receiver_id = ? AND receiver_type = 'User') OR (sender_id = ? AND sender_type = 'User')", store_id, store_id)}
```