Commit Graph

16 Commits

Author SHA1 Message Date
Santiago Pastorino
ea3566955c Remove option method just use the reader 2013-05-21 17:03:06 -07:00
Santiago Pastorino
5017fb686a Associations doesn't depend on source serializer anymore 2013-05-21 17:03:06 -07:00
Santiago Pastorino
460a250984 Get rid of refine 2013-05-21 17:03:06 -07:00
Gosha Arinich
e8ae3e1bb3 allow singular embed when serializing association
Having

```ruby
has_one :post, embed: :ids
```

looks especially weird as it's a one-to-one association, hence there is
only one id. The following looks better:

```ruby
has_one :post, embed: :id
```
2013-05-05 11:02:42 +03:00
Sean Abrahams
79acd87829 Use method instead of asssociation_ids if method exists. Fixes #267 2013-04-10 14:38:53 -07:00
Sam
af13d48dfa improved caching of root node for better performance 2013-03-18 16:21:34 -07:00
tchak
e2c10f4440 use read_attribute_for_serialization to serialize ids
* in order to allow some optimisation in simple cases, we call `read_attribute_for_serialization` on parent with association_id name
2013-03-08 09:57:42 +01:00
Jeremy Redburn
7cd7d295e0 Adding 'embed_key' option to allow embedding attributes other than ID 2013-03-05 18:52:31 -05:00
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
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
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
a854c1b9dc use id methods 2012-12-20 13:21:37 -05: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