Commit Graph

92 Commits

Author SHA1 Message Date
Santiago Pastorino
e295af2e2b Move embed methods to initialize and define readers 2013-05-21 17:03:08 -07:00
Santiago Pastorino
cd9e106640 All the attr_readers together 2013-05-21 17:03:08 -07:00
Santiago Pastorino
1c3f14407c There's no need for target_serializer method 2013-05-21 17:03:08 -07:00
Santiago Pastorino
feaefeeef3 Use name reader 2013-05-21 17:03:08 -07:00
Santiago Pastorino
296970415a Move key method to the base class 2013-05-21 17:03:08 -07:00
Santiago Pastorino
ecbb8bf6a6 Use == || == instead of include? 2013-05-21 17:03:08 -07:00
Santiago Pastorino
eb5b27de69 Initialize things in the initialize method and define readers 2013-05-21 17:03:08 -07:00
Santiago Pastorino
ea6d712cc8 key method is defined on subclasses 2013-05-21 17:03:07 -07:00
Santiago Pastorino
2dd0090f13 Reorder methods 2013-05-21 17:03:07 -07:00
Santiago Pastorino
0b648fceac Use private instead of protected, we don't use explicit receivers 2013-05-21 17:03:07 -07:00
Santiago Pastorino
f9e189e9d7 Rename associated_object to object 2013-05-21 17:03:07 -07:00
Santiago Pastorino
85bf3d2f3d Move duplicated code to the Base class 2013-05-21 17:03:07 -07:00
Santiago Pastorino
03669a74bc Associations::Config is now Associations::Base 2013-05-21 17:03:07 -07:00
Santiago Pastorino
e273a2fb37 Use a third argument to pass serializer_options 2013-05-21 17:03:07 -07:00
Santiago Pastorino
c04d452823 Associations doesn't depend on the source serializer anymore :) 2013-05-21 17:03:07 -07:00
Santiago Pastorino
c1e710aae1 Save result of calling associated_object in a local var 2013-05-21 17:03:06 -07:00
Santiago Pastorino
baa690a01a Move if object to the top 2013-05-21 17:03:06 -07:00
Santiago Pastorino
0917148617 serialize_ids doesn't use source serializer and it's object 2013-05-21 17:03:06 -07:00
Santiago Pastorino
9f5e872621 Extract id_key to a method 2013-05-21 17:03:06 -07:00
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
Santiago Pastorino
1a8709d71c Move caching to a new module 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
Steve Klabnik
9551a97464 Revert 37b0690fb8.
This feature causes more problems than it solves.
2013-04-03 17:24:08 -07:00
Steve Klabnik
680e2efbec Merge pull request #246 from beerlington/dry-option-setup
Refactor and consolidate serializer option setup
2013-03-20 08:56:54 -07:00
beerlington
fd578fcf69 Refactor and consolidate serializer option setup 2013-03-19 22:21:41 -04:00
Sam
af13d48dfa improved caching of root node for better performance 2013-03-18 16:21:34 -07:00
beerlington
4a13f86961 Reference scope by same name as serialization scope
By default, the serialization scope uses current_user, and you can
now reference the scope as "current_user" in the serializer. If you
override the scope using "serialization_scope" in your controller,
it will use that method name instead.
2013-03-18 14:44:38 -04:00
Tony Pitale
d3c6596990 make sure to merge the original responder options into the given options to preserve location 2013-03-15 03:54:35 -04:00
Michael Rykov
37b0690fb8 Add a Responder to handle respond_with(resource) 2013-03-13 16:45:23 -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