rodrigoalvesvieira
rodrigoalvesvieira

Reputation: 8062

Relationships with Spree::Products

I'm using Spree in my Rails 3.2 app and I'd like to know how can I create relationships between some models I'have defined myself and Spree::Product.

For example, in a clothing store I'd like do group products (Spree::Product) by Collection (now Collection is a hypothetical model of mine).

How do I declare a has_many relationship in Collection in respect to Spree::Product objects?

P.S: I've tried both has_many :products and has_many :spree_products within my model and none of them works.

Upvotes: 1

Views: 752

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

If you want to define this method on Spree::Product objects then you will need to use a decorator. Add this code to app/models/spree/product_decorator.rb within your application:

Spree::Product.class_eval do
  has_many :collections
end

Now each Spree::Product object will respond to a collections method.

Upvotes: 2

Related Questions