Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with behaviors in Doctrine
    primarykey
    data
    text
    <p>I have a problem in one of my projects, where I'm using Doctrine as an ORM.</p> <p>For some reason, when rebuilding the models and database structure, Doctrine ignores the behaviors and relations, I define in one of the table definitions. The YAML table definition looks like this:</p> <pre><code>... User: actAs: Timestampable: Sluggable: unique: true fields: username canUpdate: true columns: id: type: integer(4) primary: true autoincrement: true company_id type: integer(4) timezone_id: type: integer(1) role_id: type: integer(1) email: type: string(255) username: type: string(255) unique: true password: type: string(40) firstname: type: string(255) lastname: type: string(255) last_login: type: datetime relations: Company: local: company_id foreign: id Timezone: local: timezone_id foreign: id Role: local: role_id foreign: id ... </code></pre> <p>The generated table structure looks like this:</p> <pre><code>CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `company_id` int(11) DEFAULT NULL, `timezone_id` tinyint(4) DEFAULT NULL, `role_id` tinyint(4) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, `password` varchar(40) DEFAULT NULL, `firstname` varchar(255) DEFAULT NULL, `lastname` varchar(255) DEFAULT NULL, `last_login` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code></pre> <p>As you can see, Doctrine generates all the columns I define, but for some reason all the stuff that is supposed to happen automatically is not done. First of all, it doesn't create the <code>updated_at</code> and <code>created_at</code> columns for the Timestampable behavior and the <code>slug</code> column for Sluggable behavior is also missing.</p> <p>The indexes and foreign key constraints are also missing.</p> <p>When I open up the generated model class, it looks all fine:</p> <pre><code>class BaseUser extends Doctrine_Record { .... public function setUp() { parent::setUp(); $this-&gt;hasOne('Company', array( 'local' =&gt; 'company_id', 'foreign' =&gt; 'id')); $this-&gt;hasOne('Timezone', array( 'local' =&gt; 'timezone_id', 'foreign' =&gt; 'id')); $this-&gt;hasOne('Role', array( 'local' =&gt; 'role_id', 'foreign' =&gt; 'id')); $timestampable0 = new Doctrine_Template_Timestampable(); $sluggable0 = new Doctrine_Template_Sluggable(array( 'unique' =&gt; true, 'fields' =&gt; 'username', 'canUpdate' =&gt; true, )); $this-&gt;actAs($timestampable0); $this-&gt;actAs($sluggable0); } .... } </code></pre> <p>So, the problem lies in the SQL query generation...</p> <p>Has anyone else experienced a similar problem, or can you spot any errors in my YAML definition?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload