Documentation of ClassMetadataInfo::$associationMapping lacks information about joinColumns #5034

Closed
opened 2026-01-22 14:57:02 +01:00 by admin · 1 comment
Owner

Originally created by @holtkamp on GitHub (Mar 5, 2016).

Originally assigned to: @Ocramius on GitHub.

It seems that the documentation of the ClassMetadataInfo::$associationMapping property does not describe the joinColumns entry. It does describe the joinTable entry.

I needed information about the joinColum to determine whether a one-to-one association was marked as nullable. Something like this seems to provide the proper information (assuming we already know it is an association we are talking about).

private function isAssociationNullable(ClassMetadataInfo $metadata, string $fieldName) : bool
    {
        assert($metadata->hasAssociation($fieldName));
        $mapping = $metadata->getAssociationMapping($fieldName);
        if(isset($mapping['joinColumns'], $mapping['joinColumns'][0], $mapping['joinColumns'][0]['nullable']) ){
            return $mapping['joinColumns'][0]['nullable'] === true;
        }

        return false; //Information not available? Just to be sure
    }
Originally created by @holtkamp on GitHub (Mar 5, 2016). Originally assigned to: @Ocramius on GitHub. It seems that [the documentation](https://github.com/doctrine/doctrine2/blob/c1943624ab1260c629316bab104dc5130c060154/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L477-L532) of the `ClassMetadataInfo::$associationMapping` property does not describe the `joinColumns` entry. It _does_ describe the `joinTable` entry. I needed information about the joinColum to determine whether a one-to-one association was marked as nullable. Something like this seems to provide the proper information (assuming we already know it is an association we are talking about). ``` php private function isAssociationNullable(ClassMetadataInfo $metadata, string $fieldName) : bool { assert($metadata->hasAssociation($fieldName)); $mapping = $metadata->getAssociationMapping($fieldName); if(isset($mapping['joinColumns'], $mapping['joinColumns'][0], $mapping['joinColumns'][0]['nullable']) ){ return $mapping['joinColumns'][0]['nullable'] === true; } return false; //Information not available? Just to be sure } ```
admin added the DocumentationInvalid labels 2026-01-22 14:57:02 +01:00
admin closed this issue 2026-01-22 14:57:03 +01:00
Author
Owner

@holtkamp commented on GitHub (Oct 28, 2016):

seem to have overlooked this line: c1943624ab/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (L525)

@holtkamp commented on GitHub (Oct 28, 2016): seem to have overlooked this line: https://github.com/doctrine/doctrine2/blob/c1943624ab1260c629316bab104dc5130c060154/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L525
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5034