Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with decorate_association for STI #490

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

problem with decorate_association for STI #490

artempartos opened this issue Mar 6, 2013 · 2 comments

Comments

@artempartos
Copy link
Contributor

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
Copy link
Contributor Author

the simplest solution here #491

@anatoliypronin
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants