I have three model:

* raw\_coupon
* coupon
* store

If I'm looping through raw\_coupons, how can I save it as a coupon only if the same coupon\_code doesn't already exist for that store? Here is code to make it more clear:

```
raw_coupon.each do |raw_coupon|
  coupon = Coupon.new
  coupon.store_id = raw_coupon.store_id
  coupon.coupon_code = raw_coupon.coupon_code

  coupon.save if [coupon_code for this store doesn't already exist]
end

```

How to I write out the **[coupon\_code for this store doesn't already exist]**

**NOTE:** more than one store can be using the same coupon code hence I need to check if the same coupon\_code exists for that store specifically.

**EDIT:** Here are the model associations:

* raw\_coupon: has\_one :coupon
* coupon: belongs\_to :raw\_coupon && belongs\_to:store
* store: has\_many :coupons