Closed krainboltgreene closed 8 years ago
This works, you just have to do as follows.
class Cart::Twin < Disposable::Twin
collection :nikes, twin: ItemTwin
def nikes
super model.items.nikes
end
end
Oooh, that's a great example, should be in the readme.
Actually, that doesn't work :(
Are you sure about the syntax?
Never ever again say "this doesn't work" anymore in a programming context. Please.
What happens?
BTW, I love your blog, you should blog more. :rocket:
Well first I noticed you used Cart::Twin
, so I guessed you either made a typo or you're namespacing to cart. Second, you're defining the collection on either Cart
or this new Cart::Twin
object, the former results in ActiveRecord saying "Hey, nikes isn't a method I know about for Cart" and the second way results in the same error as the original ticket.
@krainboltgreene Jump on https://gitter.im/trailblazer/chat we can figure it out there ;)
So in-between writing a monkey patch to add subsets for my application I realized another approach that is less than easy to understand but works:
class CartTwin
property :items, twin: ItemCollectionTwin
end
class ItemCollectionTwin
collection :nikes, twin: ItemTwin
end
That's ingenious!
So, you basically could macro-ize that in a Scope
feature model. What do you think? And that could be marked as writeable: false
, as discussed in the other issue that I can't find.
The Scope
feature module being part of Disposable, of course! :beer:
lib/disposable/presentation/scope.rb
or something...
See #26 #23 latest and once we finish those discussions I'll start a PR that adds this special functionality.
Which would you prefer: extension gem (disposable-activerecord
or something) or directly in disposable?
Sorryyyy for the delay! Let's do a disposable-orm
gem, since scopes are pretty generic. We can discuss everything based on your code, then.
Does that sound good?
Sooooo as someone who does a lot of foss projects I hate to say this, but I think we're going to reimplement disposable's use case (soft application) in a new library internally and possibly release.
Meaning it might be useful to just close these issues.
Oh I've heard that many times and then never seen any free OSS code based on the original stuff. Good luck!
Eager to hear your ideas, what you will change.
I realize
#scopes
is a feature specific to ActiveRecord and this library is pretty agnostic. Here's an example:With this library it raises an error:
I'm not sure how it would work, but I would love to see this: