dflydev / dflydev-doctrine-orm-service-provider

Doctrine ORM Service Provider
MIT License
209 stars 59 forks source link

Issue with mappings #64

Open casoetan opened 9 years ago

casoetan commented 9 years ago

Hi, I'm working on using two mappings in app.php, see below

$app->register(new DoctrineOrmServiceProvider, [
  'orm.proxies_dir' => __DIR__.'/../var/cache/doctrine/Proxy',
  'orm.em.options' => [
    'mappings' => [
      // Using actual filesystem paths
      [
        'type' => 'annotation',
        'use_simple_annotation_reader' => false,
        'namespace' => 'Auth\entities',
        'path' => __DIR__.'/auth/entities',
      ],
      [
        'type' => 'annotation',
        'use_simple_annotation_reader' => false,
        'namespace' => 'Profile\entities',
        'path' => __DIR__.'/profile/entities',
      ],
    ],
  ],
]);

my entities are

<?php
namespace Auth\entities;

use Doctrine\ORM\Mapping;
use Doctrine\Common\Annotations\Annotation;

use Symfony\Component\Security\Core\User\AdvancedUserInterface;

use Profile\entities\Profile;

/**
* @Mapping\Entity(repositoryClass="Auth\entities\repositories\UserRepository")
* @Mapping\Table(name="users")
* @Mapping\HasLifecycleCallbacks()
*/
class User implements AdvancedUserInterface, \JsonSerializable {

  public $name = 'Auth\entities\User';
  /**
   * @Mapping\Id @Mapping\Column(type="integer")
   * @Mapping\GeneratedValue
  */
  protected $id;

  /**
   * @Mapping\Column(type="string", unique=true)
   */
  protected $email;

  /** @Mapping\Column(type="string") */
  protected $password;

  /** @Mapping\Column(type="string") */
  protected $salt;

  /** @Mapping\Column(type="array") */
  protected $roles;

  /**
   * @Mapping\OneToOne(targetEntity="\Profile\entities\Profile", mappedBy="user")
   * @var Profile
  **/
  protected $profile;

the other entity is

namespace Profile\entities;

use Doctrine\ORM\Mapping;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Mapping\ClassMetadata;

use Auth\Entities\User;

/**
* @Mapping\Entity(repositoryClass="Profile\entities\repositories\ProfileRepository")
* @Mapping\Table(name="profiles")
*/
class Profile implements \JsonSerializable {
  /**
   * @Mapping\Id @Mapping\Column(type="integer")
   * @Mapping\GeneratedValue
  */
  protected $id;

  /** @Mapping\Column(type="string", nullable=true) */
  protected $salutation;

  /** @Mapping\Column(type="string", name="first_name") */
  protected $firstName;

  /** @Mapping\Column(type="string", name="last_name") */
  protected $lastName;

  /** @Mapping\OneToOne(targetEntity="Auth\Entities\User", inversedBy="profile") */
  protected $user;

but when I try to get any of these entities, an error returns

{
  "error": true,
  "statusCode": 500,
  "message": "An exception occurred while executing 'SELECT t0.id AS id_1, t0.email AS email_2, t0.password AS password_3, t0.salt AS salt_4, t0.roles AS roles_5, t0.imageUrl AS imageUrl_6, t0.domain_slug AS domain_slug_7, t0.enabled AS enabled_8, t0.not_expired AS not_expired_9, t0.valid_credentials AS valid_credentials_10, t0.not_locked AS not_locked_11, t0.invite_token AS invite_token_12, t0.invited AS invited_13, t0.access_token AS access_token_14, t0.confirmation_token AS confirmation_token_15, t0.last_password_updated AS last_password_updated_16, t0.created_at AS created_at_17, t0.updated_at AS updated_at_18, t0.type_id AS type_id_19, t20.id AS id_21, t20.salutation AS salutation_22, t20.first_name AS first_name_23, t20.last_name AS last_name_24, t20.gender AS gender_25, t20.birthdate AS birthdate_26, t20.created_at AS created_at_27, t20.updated_at AS updated_at_28, t20.user_id AS user_id_29, t20.church_id AS church_id_30, t20.cell_id AS cell_id_31 FROM users t0 LEFT JOIN profiles t20 ON t20.user_id = t32.id WHERE t0.access_token = ? LIMIT 1' with params [\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImNoYXJsZXNAZ21haWwuY29tIiwicGFzc3dvcmQiOiJsMnVaMnowblRGZ1pOakZyT0g5Y3FJQlwvamxOWmhkSStEY1lITCtBcUh4R25pZnhnbzNvVkYrVHdvVTJZY09lK24wRm1wOTdJQXRPakpGQUhOZUNCSEE9PSIsInJvbGVzIjpbIlJPTEVfU1RBUlRFUiIsIlJPTEVfU1VQRVJfQURNSU4iLCJST0xFX1VTRVIiXSwidGltZSI6eyJkYXRlIjoiMjAxNS0xMC0wOCAwNzo1MDowMy4wMDAwMDAiLCJ0aW1lem9uZV90eXBlIjozLCJ0aW1lem9uZSI6IkFmcmljYVwvTGFnb3MifX0.PCqwqTvcK83lRUnOfHkN4b3eQ_iAaFkJ7JaLStGopfc\"]:\n\nSQLSTATE[42S22]: Column not found: 1054 Unknown column 't32.id' in 'on clause'"
}

The sql is incorrectly trying to reference a column that does not exist. Is there a way to use two mappings or I'm i stuck with one?