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

Twin Twin works, Twin Twin Relationship Twin doesn't work #29

Open
krainboltgreene opened this issue Nov 30, 2015 · 4 comments
Open

Twin Twin works, Twin Twin Relationship Twin doesn't work #29

krainboltgreene opened this issue Nov 30, 2015 · 4 comments

Comments

@krainboltgreene
Copy link

Okay, so the title is a bit screwey, but here's the example:

class CartTwin
  collection :redemptions, twin: RedemptionTwin

  property :discount_cents
end

class RedemptionTwin
  property :cart
end

Okay, everything looks good so far.

cart = Cart.find_by(id: '...')
cart.redemptions.count # => 2
cart.redemptions.map(&:class) # => [Redemption, Redemption]
cart.class # => Cart

twin = CartTwin.new(cart)
twin.redemptions.count # => 2
twin.redemptions.map(&:class) # => [RedemptionTwin, RedemptionTwin]
twin.redemptions.map(&:model).map(&:class) # => [Redemption, Redemption]
twin.class # => CartTwin
twin.model.class # => Cart

Still fine, but now:

shadow = CartTwin.new(twin)
shadow.class # => CartTwin
shadow.model # => Cart

Amazing! Each new subsequent twinning will pick up the correct properties, but know the right model. Perfect, until...

shadow.redemptions.map(&:class) # => [RedemptionTwin, RedemptionTwin]
shadow.redemptions.map(&:model).map(&:class) # => [RedemptionTwin, RedemptionTwin]

Uh-oh.

shadow.redemptions.map(&:model).map(&:model).map(&:class) # => [Redemption, Redemption]
@apotonick
Copy link
Owner

Hahahaha I love that title! ❤️

@krainboltgreene
Copy link
Author

<3

@krainboltgreene
Copy link
Author

Amazing! Each new subsequent twinning will pick up the correct properties, but know the right model.

Turns out I was wrong about this. I was very sure this was the case when I tried it a week ago, but it no longer seems to be the case.

@krainboltgreene
Copy link
Author

So I guess this isn't a bug, so much as a feature request now.

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