problem with decorate_association for STI #490

Closed
artempartos opened this Issue Mar 6, 2013 · 2 comments

3 participants

@artempartos

In last tag (1.1.0) i have problems with STI, both with decorating collection and decorating association.

I have next models:

class Product < ActiveRecord::Base 
  has_many :product_similar_product_relationships, foreign_key: 'product_id', inverse_of: :product, as: :product
  has_many :similar_products, through: :product_similar_product_relationships
  has_many :packages
end

class ProductSimilarProductRelationship < ActiveRecord::Base
  belongs_to :product, inverse_of: :product_similar_product_relationships, polymorphic: true
  belongs_to :similar_product, class_name: Product
end

class Product::Package < ActiveRecord::Base 
belongs_to :product
end

Product and Product::Package are STI, so:

class Candle < Product, 
class Book < Product 
...
class Candle::Package < Product::Package
class Book::Package < Product::Package

and so on

And i have decorators:

class ApplicationDecorator < Draper::Decorator
  delegate_all
end

class ProductDecorator < ApplicationDecorator
  decorates :product
  def ...  end
end

class CandleDecorator < ProductDecorator
  decorates :candle
  decorates_association :packages
  decorates_association :similar_products
  def ...  end
end

class BookDecorator < ProductDecorator
  decorates :book
  decorates_association :packages
  decorates_association :similar_products
  def ...  end
end
  1. DecorateCollection If i do in console:
Product.scoped.limit(2).decorate
=> #<Draper::CollectionDecorator of ProductDecorator for [...]>

But i expect Draper::CollectionDecorator of inferred decorators where each Product was decorated with its own decorator.
2. DecorateAssocation
If i do in console:

Product.first.decorate.similar_products
=> #<Draper::CollectionDecorator of ProductDecorator for [...]>

But i also expect Draper::CollectionDecorator of inferred decorators

As i know, some time ago, in commit 44f4c18 first trouble was fixed. But it doesn't work for second trouble

@artempartos

the simplest solution here #491

@anatoliypronin

Face with problem! I hope next release fix this problem.

@artempartos artempartos added a commit to artempartos/draper that referenced this issue Mar 10, 2013
@haines haines Use source.decorate when decorator is not specified
Closes #490
68ab683
@haines haines closed this in f64859e Mar 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment