Core: Error when trying to get subresource binded by OneToOne relation

Created on 29 Mar 2018  ยท  5Comments  ยท  Source: api-platform/core

There are two entity Users and Profile.
They binded by OneToOne relation via fields:

  • $profile in Users entity (inverse side)
  • $user in Profile entity (owning side)

Field $profile has @API\ApiSubresource() annotation. Api-platform creates route /api/users/1/profile.

But when I try to GET data by this URL I occurs an error:

Type error: Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinColumnName() must be of the type array, boolean given, called in C:\TEST\backend\vendor\doctrine\orm\lib\Doctrine\ORM\Query\AST\Functions\IdentityFunction.php on line 89

In case of using either ManyToOne or OneToMany associations all working perfectly.

Users.php

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation as API;
use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity()
 *
 * @API\ApiResource()
 */
class Users
{
    /**
     * @var int
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var Profile
     * @ORM\OneToOne(targetEntity="Profile", mappedBy="user")
     * @API\ApiSubresource()
     */
    private $profile;

// Other properties, getters and setters next ...
}

Profile.php

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation as API;
use Doctrine\ORM\Mapping as ORM;


/**
 * @ORM\Entity()
 *
 * @API\ApiResource()
 */
class Profile
{
    /**
     * @var int
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var Users
     * @ORM\OneToOne(targetEntity="Users", inversedBy="profile")
     * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
     */
    private $user;

// Other properties, getters and setters next ...
}
Has a PR bug โญ EU-FOSSA Hackathon

Most helpful comment

Any clue about this? Got the same error...

All 5 comments

Could you please provide a reproducer for this ?

@Simperfit Here you are https://github.com/and-xdev/api-test

  1. clone repository
  2. set up .env for DB etc.
  3. Load database schema and data from api-test.sql file in the root of the project

Routes:
/api/users/1/profile - does not work
/api/users/1/balances - works

Any clue about this? Got the same error...

I found the issue, and created PR for solving it: https://github.com/api-platform/core/pull/2228. Hopefully it will be ok, and could be merged.

Is fixed!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

soyuka picture soyuka  ยท  3Comments

kate-kate picture kate-kate  ยท  3Comments

CvekCoding picture CvekCoding  ยท  3Comments

mahmoodbazdar picture mahmoodbazdar  ยท  3Comments

gustawdaniel picture gustawdaniel  ยท  3Comments