Doctrine ORM Entity ManyToOne with Concrete User

Permalink 1 user found helpful
I'm trying to figure out using Doctrine within a custom package in Concrete5.7.

I'm using:

# concrete5 Version
Core Version - 5.7.4.2
Version Installed - 5.7.4.2
Database Version - 20150504000000


And I'm building off the Mainio DBEntities example:
https://github.com/mainio/c5_entities_example...

based on:
https://github.com/mainio/c5pkg_dbentities... package.

In my entities, you'll see they all extend BaseEntity. BaseEntity is just my "wrapper class" for the Mainio_DBEntities example. It's just
<?php
namespace Concrete\Package\DOMAINCore\Src\Entity;
use Mainio\C5\Entity\Entity;
use ORM;
abstract class BaseEntity extends Entity
{
}

and I have a couple of my own functions in there, mainly convenience functions.

I've dealt with doctrine entities in the past, but one thing seems to be an issue...

I have a manyToMany through a table. So I have Events and Hosts, and an EventHost is the many to many. However, EventHost is being used because a "Host" should just be a concrete 5 user in the system, other than that there's noting else special about that mapping. (Please ignore some of the column name overrides from the default unless it applies to the issue, because I'm trying to migrate an existing db schema).

So, My Entites look like this:
<?php
namespace Concrete\Package\DOMAINCore\Src\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * @Entity
 * @Table(name="DOMAINEvent")
 */
class Event extends BaseEntity implements \JsonSerializable
{
    public function __construct()
    {
        $this->hosts= new ArrayCollection();
    }
    /**
     * @Id @Column(type="integer")


<?php
namespace Concrete\Package\DOMAINCore\Src\Entity;
/**
 * @Entity
 * @Table(name="DOMAINEventHosts")
 */
class EventHost extends BaseEntity implements \JsonSerializable
{
    /**
     * @Id @Column(type="integer")
     * @GeneratedValue
     */
    protected $eventHostId;
    /**
     * @ManyToOne(targetEntity="Event", cascade={"all"})


Now, in EventHost, I would like:
/**
     * @Column(targetEntity="User", cascade={"all"})
     * @JoinColumn(name="userId", referencedColumnName="userId")
     */
    protected $userId;


but I can't because the User is not a managed entity by Doctrine so it doesn't know what I'm talking about. I've tried full path to the class, importing it with a non-conflicting alias just to try, and neither worked.

Has anyone done any kind of association with the Concrete user and had success? I'm guessing I have to make a proxy class that just maps userId to DOMAINUserId or something like that and have a bunch of extraneous tables?

Keep in mind, all other entities are fine, their schemas are build in the db, simple tests of creating objects with associations are persisted, etc. But adding this association to EventHost, the schema is not updated no matter what I do (unless i just make userId an integer column as it is there).

Also, if anyone has any tips how to better work in c5 with Doctrine, I'd appreciate them. Such as how to run orm:validate-schema within the c5 stack so classes are available and loaded correctly, that would be awesome!

jimic79
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi jimic79,

I am not sure if this will assist you.
https://github.com/hissy/c5_example_entity...
hissy replied on at Permalink Reply
hissy
My example package has a most simple entity. I'm not sure with manyToMany entity type. Sorry.
dorianmarchal replied on at Permalink Reply
dorianmarchal
This package helped me a lot :https://github.com/mainio/c5_entities_example...
hutman replied on at Permalink Reply
hutman
I was able to do this in 5.8 (not sure what all is different) by doing this

/**
 * One Store has One User
 * @OneToOne(targetEntity="Concrete\Core\Entity\User\User")
 * @JoinColumn(name="user_id", referencedColumnName="uID")
 */
protected $user;