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

accessing #acting_as through association returns the wrong actable #50

Open
risen opened this issue Nov 5, 2015 · 2 comments
Open

accessing #acting_as through association returns the wrong actable #50

risen opened this issue Nov 5, 2015 · 2 comments

Comments

@risen
Copy link

risen commented Nov 5, 2015

There seems to be a problem if you have a circular dependency in your actable base class.

Example:

class Product < ActiveRecord::Base
  actable
  belongs_to :pen_case
end

class Pen < ActiveRecord::Base
  acts_as :product
end

class PenCase < ActiveRecord::Base
  acts_as :product
  has_many :products
end

As you can see Product has a reference pen_case_id to PenCase, which again, is a Product.

Now, this happens:

>> PenCase.first.products
+----+------------+--------------+-------------+--------+-------+
| id | actable_id | actable_type | pen_case_id | name   | price |
+----+------------+--------------+-------------+--------+-------+
| 1  | 1          | Pen          | 1           | Penie! | 0.8   |
+----+------------+--------------+-------------+--------+-------+
1 row in set
>> Pen.first.product.id
=> 1
>> PenCase.first.product.id
=> 2
>> Pen.first.pen_case.product.id
=> 1

As you can see accessing #product (or #acting_as) gives the wrong result if we go through the Product#pen_case association. Weird?

@risen
Copy link
Author

risen commented Nov 5, 2015

@hzamani
Copy link
Owner

hzamani commented Jan 24, 2016

Why there should be such a circular dependency in model?

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

2 participants