Hi

I got abstract class User

<entity name="User" table="users" inheritance-type="JOINED" >

    <discriminator-column name="discriminator" type="string"/>
    <discriminator-map>
        <discriminator-mapping value="employee" class="Employee"/>
    </discriminator-map>

    <id name="id" type="integer" column="id">
        <generator strategy="AUTO"/>
        <options>
            <option name="unsigned">true</option>
        </options>
    </id>

    <field name="gender" type="boolean" nullable="false" />

</entity>


abstract class User
{
    /**
     * @var int
     */
    protected $id;
    
    /**
     * @var bool
     */
    protected $gender;

    public function __construct($gender)
    {
        $this->gender = $gender;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
}



and Employee 

<entity name="Employee" table="employees" >

    <field name="location" type="int" />

</entity>


class Employee extends User
{
    /**
     * @var int
     */
    protected $location;

    public function __construct($gender, $location)
    {
        parent::__construct($gender);
        $this->location = $location;
    }
}



Normally I just use

$employee = new Employee(false, 1);
$this->em->persist($employee);
$this->em->flush($employee);


and it works like it should but if I want to set id manually

$employee = new Employee(false, 1);
$employee->setId(1);
$metadata = $this->em->getClassMetaData(get_class($employee));
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$this->em->persist($employee);
$this->em->flush($employee);



insert to table users is incorrect, there is no 'id' so it use auto 
generated id

INSERT INTO users (gender) VALUES (?)
array(2) {
        [1]=>
            bool(1)
}
array(2) {
        [1]=>
            string(7) "boolean"
}




but insert to employees is correct. Notthing is saved to database 
(rollback) because ids are diffrent

INSERT INTO employees (id, location) VALUES (?, ?)
array(2) {
        [1]=>
            int(1)
        [2]=>
            int(1)
}
array(2) {
        [1]=>
            string(7) "integer"
        [2]=>
            string(7) "integer"
}



I'm using MySQL if this is important.
With normal entities it works but with Class Table Inheritance dont work. 
Can anyone help? Am I doing something wrong?
















-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to