I’m using Doctrine ORM in a project that I am working on. Although the idea of providing an object interface to the db is nice, I have a question about the implementation of the entity classes.
Let’s consider this example of a User entity:
<?php
/**
* @Entity @Table(name="users")
**/
class User
{
/**
* @Id @GeneratedValue @Column(type="integer")
* @var int
**/
protected $id;
/**
* @Column(type="string")
* @var string
**/
protected $name;
/**
* @OneToMany(targetEntity="Bug", mappedBy="reporter")
* @var Bug[]
**/
protected $reportedBugs = null;
/**
* @OneToMany(targetEntity="Bug", mappedBy="engineer")
* @var Bug[]
**/
protected $assignedBugs = null;
// .. (other code)
}
Now, its all fine and dandy, but I was wondering what would happen if I make a spelling mistake in one of the comments e.g. I write:
@Table(name="users)
instead of
@Table(name="users")
the IDE will not complain since its a comment, and I’ll only get an error when I run the “generate entities” command (that does the magic in the background of generating code, creating tables, columns and relationships).
So my question is: Aren’t entity definitions for ORM error prone? since there really is no check on the syntax if its valid, and errors are generated only at ‘generate’ time. Is there a way to automate / check for mistakes earlier on while development?
Thanks!
IMO, The issue that you highlighted can be compared to using wrong variables in PHP ($var1 instead of $var2). For that matter, in all dynamic languages.
But you can avoid the problem highlighted by you, if you write unit tests.