24 Commits

Author SHA1 Message Date
Johannes Vetter
d7f6963afc Links on a relationship can take a callable 2021-01-16 11:45:37 -08:00
mperice
dd7f5ba415
Add optional meta field to relationships (#99) (#100)
* Add optional meta field to relationships (#99)

* Fix Rubocop's warnings.

* Minor syntax corrections.
2020-07-07 15:22:25 +01:00
Kevin Pheasey
1d2eab2510
fix(Relationship): do not set static_record_type for polymorphic relationships (#82) 2020-05-18 10:09:58 -04:00
Stas SUȘCOV
c533634293 Rewrite tests. 2020-04-29 15:30:44 +01:00
Stas SUȘCOV
12e2987420 Rubocop cleanups. 2020-04-29 15:30:44 +01:00
Attila Horvath
3faca2d1e0 Fix conditional procedures with lambdas 2020-02-21 14:36:50 +00:00
Attila Horvath
08a20d0ebb Fix relationships with &:proc shorthands 2020-02-20 13:44:18 +00:00
Christopher Sansone
6d01bec146
Improved relationship serializer options (#32)
* allow the relationship's serializer key to be a Proc

* fixes

* specifically test the relationship name and the resource type

* support object blocks without a serializer defined

* stop validation gracefully if the relationship is polymorphic

* improve performance by using instance variables instead of accessor methods

* force initialization up front to avoid the iterative calls

* serializer procs should act like polymorphic when determining the id_method_name

* specs for serializer procs

* updated with more details and examples for relationship serializer options

* adjust specs to define the serializers

* avoid extra method calls for performance

* name change

* one less function call for better performance

* do not require lazy loaded relationships to resolve the serializer

* give polymorphic precedence for backwards compatibility

* move serializer inference into ObjectSerializer to allow for overriding

* move method for better diff

* fix race condition in multi-threaded environments
2020-02-15 14:57:44 +00:00
Aubrey Holland
1d7c18f5da Support for polymorphic id_method_name (#17)
* fix id method bugs, add specs
* Use SecureRandom.uuid
2019-12-03 18:04:04 +00:00
David Pickart
8e2383128e Include data key when lazy-loaded relationships are specified with includes (#10) 2019-10-08 08:30:21 -04:00
Jo Potts
83e99b2923 Allow relationship links to be declared as object method (#2)
* Allow relationship links to be declared as object method

* Relationship links note added to readme
2019-10-04 12:50:22 -04:00
nikz
1ad20d6b7b Merge branch 'upstream-dev' into add-links-option-to-relationship-serializer 2018-10-07 21:29:43 +01:00
nikz
85b41c45d4 Adds :lazy_load_data option
If you include a default empty `data` option in your JSON API response,
many frontend frameworks will ignore your `related` link that could be
used to load relationship records, and will instead treat the
relationship as empty.

This adds a `lazy_load_data` option which will:

  * stop the serializer attempting to load the data and;
  * exclude the `data` key from the final response

This allows you to lazy load a JSON API relationship.
2018-10-07 21:23:36 +01:00
nikz
1efdd3372d Fixes dangling comma and unused param 2018-10-02 22:09:15 +01:00
Shishir Kakaraddi
fced516356 transforms type for polymorphic relationships too 2018-09-19 20:24:40 -07:00
François Pradel
3973b312a7 Demodulize relationship record class name 2018-08-31 19:17:45 -07:00
Nik Wakelin
100f850416
Merge branch 'dev' into add-links-option-to-relationship-serializer 2018-08-05 20:58:39 +01:00
nikz
89f007d069 Adds a :links option to the relationship macros
This allows specifying a `:links` option to a has_many/has_one
relationship, which means you can specify `self` or `related` links as
per the JSON API spec (these are often useful for not loading all
associated objects in a single payload)
2018-08-05 20:37:44 +01:00
Manoj M J
0c367d2574 Minor code refactor 2018-07-21 10:05:01 +05:30
Manoj M J
9c659839e4 Evaluate ids via the specified ‘id_method_name’ when relationships are evaluated via a block 2018-07-19 15:40:20 +05:30
Kyle Reeves
01477e9c5b fix relationship id_hash method 2018-07-03 19:33:34 -07:00
Kyle Reeves
f86a8926f5 make include_relationship? a public method and use it in get_included_records method 2018-07-03 19:33:34 -07:00
Kyle Reeves
6e7d8b7ee0 make fetch_associated_object a public method on relationship class so it can be called from SerilizationCore class 2018-07-03 19:33:34 -07:00
Kyle Reeves
7b23adddc4 working on new relationship class 2018-07-03 19:33:34 -07:00