88use Swis \JsonApi \Client \Interfaces \ManyRelationInterface ;
99
1010/**
11+ * @property \Swis\JsonApi\Client\Collection|false|null $data
1112 * @property \Swis\JsonApi\Client\Collection|false|null $included
1213 */
1314abstract class AbstractManyRelation extends AbstractRelation implements ManyRelationInterface
1415{
16+ /**
17+ * @param \Swis\JsonApi\Client\Collection|null $data
18+ *
19+ * @return $this
20+ */
21+ public function setData (?Collection $ data )
22+ {
23+ $ this ->data = $ data ;
24+
25+ return $ this ;
26+ }
27+
28+ /**
29+ * @return \Swis\JsonApi\Client\Collection|null
30+ */
31+ public function getData (): ?Collection
32+ {
33+ return $ this ->data ?: null ;
34+ }
35+
1536 /**
1637 * @param \Swis\JsonApi\Client\Collection $included
1738 *
1839 * @return $this
1940 */
20- public function associate (Collection $ included )
41+ public function setIncluded (Collection $ included )
2142 {
2243 $ this ->included = $ included ;
2344
@@ -32,6 +53,33 @@ public function getIncluded(): Collection
3253 return $ this ->included ?: new Collection ();
3354 }
3455
56+ /**
57+ * @param \Swis\JsonApi\Client\Collection $included
58+ *
59+ * @return $this
60+ */
61+ public function associate (Collection $ included )
62+ {
63+ return $ this ->setData ($ included )
64+ ->setIncluded ($ included );
65+ }
66+
67+ /**
68+ * @return \Swis\JsonApi\Client\Collection
69+ */
70+ public function getAssociated (): Collection
71+ {
72+ if ($ this ->hasIncluded ()) {
73+ return $ this ->getIncluded ();
74+ }
75+
76+ if ($ this ->hasData ()) {
77+ return $ this ->getData ();
78+ }
79+
80+ return new Collection ();
81+ }
82+
3583 /**
3684 * Sort the included collection by the given key.
3785 * You can also pass your own callback to determine how to sort the collection values.
0 commit comments