-
Notifications
You must be signed in to change notification settings - Fork 137
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
Property renamed with :from is not set #10
Comments
Looks like a bug, but can you double-check if you're up-to-date, etc? Please write a provoking test, but check this first: https://github.com/apotonick/representable/blob/master/test/json_test.rb#L263 |
What I could find out: This is a Mongoid issue! Another interesting fact: I include several Mongoid classes in my user class.
If I don't include the Representer BEFORE the Mongoid includes: representable (1.0.1) lib/representable.rb:124:in `collection'
mongoid (2.4.0) lib/mongoid/contexts/mongo.rb:8:in `collection'
mongoid (2.4.0) lib/mongoid/contexts/mongo.rb:93:in `count'
mongoid (2.4.0) lib/mongoid/criteria.rb:155:in `exists?'
mongoid (2.4.0) lib/mongoid/validations/uniqueness.rb:68:in `validate_each'
activemodel (3.1.0) lib/active_model/validator.rb:153:in `block in validate'
activemodel (3.1.0) lib/active_model/validator.rb:150:in `each' But I gotta sleep now... |
Well, then Mongoid overwrites the |
It's not an general issue, as if you only include I will close this issue for now and perhaps write about a solution later. |
Hmm, it's getting worse with Mongoid. I removed all Roar includes from my model classes as my PolymorphicExtender test seems to work now, but then extending embedded objects doesn't work:
Extending fails with undefined method `representable_attrs' for Users::Profile:Class |
Paste your |
Nothing special :)
|
@chrisupb Are you sure you updated both Roar and representable to the latest version? |
Yeah I double checked it. OK I use roar-rails but it fetches No change If I use my local repos for the 3 projects. I already came up against this problem when I first used roar one month ago. But I could fix it by including roar stuff in my models. I think this is a hint, that extending doesn't work:
Error for nested profile: undefined method `representable_attrs' for #Users::Profile:0x000000050a8ac0 "Error" for normal property: private method `representable_attrs' called for #User:0x00000004913058 So an User IS extended but not the embedded profile. |
Ah, ok if you have nested objects that need a separate representer you have to use the Does that help? |
No because with "nested" I mean Mongoid embedded in this context. |
OOoook, now I get it. Can you provide a minimal app setup so I can investigate that - seems like a misunderstanding between Mongoid and Representable, maybe the #profile method doesn't return a real Profile object but some proxy or something. Thx! |
Here it is: https://github.com/chrisupb/mongoid-sample |
I reopen this one, as it's really a show blocker for me. |
Fixed in trailblazer/representable@b7eceac (1.1.1). Some strange mongoid issue that wouldn't let us set instance variables. Was ugly code anyway, so, thanks :-D Also thanks for providing a minimal example, I could very easily setup a test and fix it: trailblazer/representable@b7eceac#diff-2 |
Awesome!! Thank you. This is working now without including anything into the models. Unfortunately URL helpers are no longer available in the embedded class (instrument) undefined local variable or method `artists_url' for #<Artists::Instrument:0x00000001c16000 I updated my mongoid-example for this problem but did not yet examine it. |
…able_attrs ivar directly but use a setter. this makes it work with mongoid and fixes trailblazer/roar#10.
My user model has the property :password_confirmation and includes the UserRepresenter.
My UserRepresenter defines
I do a POST with HTTP body:
{
"passwordConfirmation":"123"
}
My controller:
Why is password_confirmation not set?
The text was updated successfully, but these errors were encountered: