Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Allow properties to be converted back to their underlying field names #19

Open
d11wtq opened this issue Jun 13, 2011 · 3 comments
Open

Comments

@d11wtq
Copy link
Contributor

d11wtq commented Jun 13, 2011

I'm working on the dm-rest-adapter code, which uses dm-serializer. Currently that code does not correctly honour :field options on properties, since it just calls #to_xml on the resource, so I'll have to post-process the result.

Perhaps a :raw => true option, or some such would be useful?

@user.to_json
# =>
{
  "id" : 42,
  "full_name" : "Testy McTesty"
  "date_of_birth" : "1980-10-01"
}

@user.to_json(:raw => true)
# =>
{
  "user_id" : 42,
  "fullname" : "Testy McTesty",
  "dob" : "1980-10-01"
}
@d11wtq
Copy link
Contributor Author

d11wtq commented Jul 3, 2011

What do I need to do to run the specs? They just error with:

/home/chris/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- dm--adapter/spec/setup (LoadError)

Most of the dm-* projects do this when I run the specs, so I assume there's some environment setting I'm supposed to set up? I'd like to submit a patch, since this is currently holding back dm-rest-adapter. I need two optional behaviours:

  1. Pay attention to :field names
  2. Include the foreign keys in the output

Currently if we PUT any resource with associations, those associations are lost because the foreign keys are not serialized. Similarly, the fields that the REST service expects must be used in the Model, when ideally we'd be able to alias them with :field, since they're not the best named fields, but we don't have control over the remote service.

If this isn't something you'd like included in dm-serializer, please let me know and I'll re-invent the wheel, so to speak, directly in dm-rest-adapter.

See README for a summary of the new functionality: https://github.com/d11wtq/dm-rest-adapter

@d11wtq
Copy link
Contributor Author

d11wtq commented Jul 3, 2011

Apologies, I see now. ADAPTER=in_memory does the trick for running the specs.

@d11wtq
Copy link
Contributor Author

d11wtq commented Jul 3, 2011

This is basically what I mean: https://github.com/d11wtq/dm-serializer/compare/master...feature/field-names

When passing the :raw option to #to_json and #to_xml, all fields and foreign keys will be serialized using their original :field names and data-types. I need to write some specs, but this seems to work. I'm half asleep so will do that during the week and submit a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant