Commit Graph

142 Commits

Author SHA1 Message Date
Steve Klabnik
95937c6fc7 Merge pull request #167 from GateGuru/feature/specify-association-serializers-as-strings
Add support for specifying the serializer for an association as a String...
2013-03-05 15:04:29 -08:00
Ismael Abreu
2d2094b588 changes to be able to specify multiple attributes with keys 2013-03-05 02:45:22 +00:00
Nicholas Mulder
918a9de546 Remove caching of Serializer constants to allow ActiveSupport::Dependency reloading to work 2013-02-28 10:02:38 -05:00
Nicholas Mulder
fa51c5f574 Add ActiveSupport::DescendantsTracker to Serializer and ArraySerializer 2013-02-28 10:01:40 -05:00
Tony Pitale
dcd4121322 reduce 2x map; fixes datamapper eager loading 2013-02-17 16:44:27 -05:00
Blake Watters
b0aced9ea2 Add support for specifying the serializer for an association as a String.
This enables the deferral of the resolution of the serializer class to prevent NameError exceptions due to reference cycles between serializer classes.
2013-01-05 23:49:28 -05:00
Steve Klabnik
e3bfd07ac4 Merge pull request #161 from kevins90/fix_attr_name_as_serializer_underscored_prefix
Fix serialization of attribute whose name matches the serializer prefix underscored
2013-01-05 14:09:15 -08:00
Steve Klabnik
7f87c9b3f2 Merge pull request #169 from dgeb/embed-with-id-suffix
Update foreign key naming conventions - fixes #158
2012-12-21 22:49:06 -08:00
Nick Ragaz
be005c6964 use _ids method instead of pluck 2012-12-21 17:35:16 -05:00
Dan Gebhardt
3b1d2faf51 Append an _id or _ids suffix to associations' keys. Embed objects in root according to their serializers' names.
An `_id` suffix will be appended to the name of HasOne associations, while `_ids` will be appended to the singularized name of HasMany associations. Association keys can still be overridden with the `key` option.

Furthermore, objects embedded in the root are now by default named according to their serializer, instead of the key used for their associations.
2012-12-21 15:14:50 -05:00
Nick Ragaz
1eb3c27a50 remove debugging code 2012-12-20 13:29:37 -05:00
Nick Ragaz
a854c1b9dc use id methods 2012-12-20 13:21:37 -05:00
Steve Klabnik
6780cd3df5 Merge pull request #138 from tchak/meta
Meta object
2012-12-10 10:48:39 -08:00
Godfrey Chan
6581f8ce41 Fix default_serializer_options, closes #112 & #113
Allow options such as :serializer, :scope, :root etc to be set via
default_serializer_options and allow the inline options to override such
defaults.
2012-12-03 03:09:58 -08:00
Kevin Tham
14a35ab2f8 Remove unneeded method aliasing of attribute reader: object, with the underscored class name of serializer, to fix issue where a model's attribute name matches that of the underscored prefix of the serializer 2012-11-25 00:17:17 -08:00
Jean Boussier
06e8218193 Throw a descriptive error if attempting to serialize an array with Serializer not ArraySerializer #143 2012-11-22 23:27:18 -05:00
Jo Liss
2fc083a1fe Merge pull request #117 from joliss/computed-attributes
Make schema not crash on computed attributes & associations
2012-11-22 08:31:18 -08:00
tchak
a71698d5bb Add support for meta key
Test for meta_key serialization
2012-11-22 13:44:59 +01:00
Samnang Chhun
96ce310595 Add alias_method ActiveModel::Serializer.root= to be consistency with ActiveModel::ArraySerializer 2012-11-20 00:29:00 +07:00
Jo Liss
538b0c0916 Make schema not crash on computed associations
We pick nil here as well.
2012-10-31 20:07:08 +01:00
Jo Liss
6281a9149e Make schema not crash on computed attributes
We do not know the type for computed attributes, so we pick nil.

Perhaps at some point we might add a :type option for attributes (or
not), but in any case it's important to not crash when there are
computed attributes.
2012-10-31 20:07:08 +01:00
Jo Liss
c767d7f5e4 Remove newly-redundant OrderedSet 2012-10-29 23:15:39 +01:00
Jo Liss
ee3cec3d0c When objects are sideloaded multiple times, serialize them only once
To achieve this, we make the following change when sideloading: Instead
of serializing associations and discarding duplicate *hashes*, we
memorize the *objects* (records) that we have already serialized, and
only serialize those that are new.

This change is mostly transparent, and brings down serialization time
from 3.1 seconds to 1.0 seconds on my set of sample data.

There is one change in the behavior: If you sideload the same object
multiple times, and it yields different hashes, like so:

    embed :ids, include: true
    has_many :comments
    has_many :recent_comments, root: comments, serializer: CommentShortSerializer

then previously, it would be included multiple times, whereas now, the
first hash wins. (I haven't actually tested this.) I don't know that
either option is preferable. It's not covered by the test suite, and I
think it's an edge case that is OK to ignore entirely.
2012-10-29 23:15:32 +01:00
Jo Liss
6be6ed8326 Extract Associations module into separate file 2012-10-29 17:21:27 +01:00
José Valim
be70c5c846 Revert "clean up lazy loading of serialization support for
ActiveRecord::Base and ActionController::Base"

The whole idea of having a lazy hook is that it can be executed
in the context of different targets. The moment you hardcode the class,
the hooks can no longer run in the proper context.

This reverts commit 506e2ac9ad.
2012-10-17 19:28:02 +02:00
Dan Gebhardt
506e2ac9ad clean up lazy loading of serialization support for ActiveRecord::Base and ActionController::Base 2012-09-20 14:23:59 -04:00
Tee Parham
9584b9e147 move OrderedSet to separate file 2012-09-18 01:28:07 +02:00
Tee Parham
b8f01ba2f3 move ArraySerializer to separate file 2012-09-18 01:28:07 +02:00
Yehuda Katz
2130cdfc00 List out the event names to avoid garbage 2012-09-16 20:20:34 -07:00
Yehuda Katz
a025f1b6f6 Eliminate some String garbage 2012-09-16 20:08:30 -07:00
Yehuda Katz
9da0176d2b Merge branch 'master' of github.com:josevalim/active_model_serializers 2012-09-16 19:46:17 -07:00
Yehuda Katz
84f8c1c3d5 Merge branch 'master' of github.com:josevalim/active_model_serializers 2012-09-02 21:21:05 -07:00
Dan Gebhardt
42221a6140 define include_XXX? methods, which can be overridden to conditionally include attributes and associations 2012-08-29 09:26:41 -04:00
Dan Gebhardt
68dc57eb73 simplified the API for include_associations!() to make conditional includes cleaner 2012-08-29 07:42:23 -04:00
twinturbo
38859d1f3d Easier to work with polymorphic interface 2012-08-25 17:39:39 +02:00
Alex Kwiatkowski & Will Bagby
754aa295ba Return empty hash when url_options not provided 2012-08-07 12:56:58 -04:00
Ray Cohen
424dacb457 scope option to render takes precedence over serialization_scope 2012-07-28 21:06:15 -04:00
Jo Liss
e8f2ecebfb Use blocks instead of eval to define methods 2012-07-26 00:28:59 +02:00
Tee Parham
663d443884 Merge branch 'array-serializer-root' of github.com:teeparham/active_model_serializers into readme-arrays 2012-07-23 13:02:04 -06:00
Tee Parham
53da0b12fd add docs for serializing arrays 2012-07-21 15:25:41 -07:00
José Valim
ef7d475912 Merge pull request #94 from teeparham/array-serializer-root
Add root option to ArraySerializer
2012-07-21 00:38:18 -07:00
José Valim
62484e758c Merge pull request #95 from twinturbo/set-serializer
Close #90
2012-07-21 00:37:31 -07:00
José Valim
6f07a0297e Merge pull request #97 from twinturbo/include-bug
Include Related Bugs
2012-07-21 00:36:04 -07:00
Chris Schmitz
a6473e70c4 Fix a couple typos. 2012-07-16 09:29:12 -05:00
twinturbo
6f3b250dc9 Don't include empty polymoprhic associations
Take this serializer:

class TodoSerializer < ActiveModel::Serializer
  root :todo, :include => true
  has_one :reference, :polymorphic => true
end

A nil reference would generate this JSON:

{
  "todo": { "reference": null },
  "nil_classes": []
}

This commit prevents the `nil_classes` key from being added when
serializing and including nil polymoprhic associations.
2012-07-16 15:08:01 +02:00
twinturbo
486d282922 Raise error when associations cannot be included
include! only works when the source serializer has a root set. The
as_json method sets up some state for the include! method. If a child
association has associations with `:include => true` or `root foo,
:include => true` would cause an undefined method error for `NilClass`.
This is entirely unhelpful for the end user.

This commit raise an error when this situation occurs. It makes it clear
that it's not a problem with AMS but the serialization graph.
2012-07-16 14:18:58 +02:00
twinturbo
7072e79787 Close #90 2012-07-15 12:18:41 +02:00
twinturbo
f01fe14972 Fix spelling mistakes 2012-07-15 11:49:36 +02:00
twinturbo
9f20fe8b36 Test passes 2012-07-15 11:49:36 +02:00
twinturbo
7e96856b87 Support serialize polymorphic id 2012-07-15 11:49:36 +02:00