Merge pull request #6715 from PowerKiKi/patch-3
Promote nullable types from PHP 7.1
This commit is contained in:
commit
f96dc3ba91
@ -238,14 +238,14 @@ the database permanently.
|
|||||||
|
|
||||||
Notice how both sides of the bidirectional association are always
|
Notice how both sides of the bidirectional association are always
|
||||||
updated. Unidirectional associations are consequently simpler to
|
updated. Unidirectional associations are consequently simpler to
|
||||||
handle. Also note that if you use type-hinting in your methods, i.e.
|
handle.
|
||||||
``setAddress(Address $address)``, PHP will only allow null
|
|
||||||
values if ``null`` is set as default value. Otherwise
|
Also note that if you use type-hinting in your methods, you will
|
||||||
setAddress(null) will fail for removing the association. If you
|
have to specify a nullable type, i.e. ``setAddress(?Address $address)``,
|
||||||
insist on type-hinting a typical way to deal with this is to
|
otherwise ``setAddress(null)`` will fail to remove the association.
|
||||||
provide a special method, like ``removeAddress()``. This can also
|
Another way to deal with this is to provide a special method, like
|
||||||
provide better encapsulation as it hides the internal meaning of
|
``removeAddress()``. This can also provide better encapsulation as
|
||||||
not having an address.
|
it hides the internal meaning of not having an address.
|
||||||
|
|
||||||
When working with collections, keep in mind that a Collection is
|
When working with collections, keep in mind that a Collection is
|
||||||
essentially an ordered map (just like a PHP array). That is why the
|
essentially an ordered map (just like a PHP array). That is why the
|
||||||
@ -396,7 +396,7 @@ There are two approaches to handle this problem in your code:
|
|||||||
|
|
||||||
1. Ignore updating the inverse side of bidirectional collections,
|
1. Ignore updating the inverse side of bidirectional collections,
|
||||||
BUT never read from them in requests that changed their state. In
|
BUT never read from them in requests that changed their state. In
|
||||||
the next Request Doctrine hydrates the consistent collection state
|
the next request Doctrine hydrates the consistent collection state
|
||||||
again.
|
again.
|
||||||
2. Always keep the bidirectional collections in sync through
|
2. Always keep the bidirectional collections in sync through
|
||||||
association management methods. Reads of the Collections directly
|
association management methods. Reads of the Collections directly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user