This project is archived and is in readonly mode.
Harmlessly make ActiveResource more MongoMapper friendly
Reported by Steve Shreeve | March 2nd, 2010 @ 04:35 AM
We're using MongoMapper with ActiveResource. Some of our model attributes begin with an underscore and also have a value that is an array (eg - "'_child' => ['bill', 'sam', 'joe']").
The typical behavior or ActiveResource is to infer a class name from the key when the value is an array. In the example above, the default is to assume that each element of the array is a member of a class called "_child". However, this will raise an exception because constants (like class names) cannot begin with an underscore. Luckily, if the actual elements of the array are simple strings or numbers, than they will be loaded as a simple array (which is what we want).
However, ActiveResource is still a bit too eager in trying to resolve the class name. If it were to simply wait to try to instantiate the inferred class until it was really needed, then everything would work fine. So, in this patch, we simply defer the constantization until it is really needed, if at all.
This simple fix makes everything work.
Comments and changes to this ticket
-
Yehuda Katz (wycats) March 28th, 2010 @ 09:55 PM
- State changed from new to incomplete
- Milestone cleared.
-
DHH May 4th, 2010 @ 05:30 PM
- Milestone cleared.
-
Santiago Pastorino February 2nd, 2011 @ 04:42 PM
- State changed from incomplete to open
- Importance changed from to Low
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:42 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>