M
M
Maxim2015-05-06 14:22:50
PHP
Maxim, 2015-05-06 14:22:50

Is it possible in Doctrine to create an entity without unique fields?

Is it possible in Doctrine to create an entity without unique fields?

/**
 * @Table(name="requests")
 * @Entity
 */
class Request extends \Data\Orm\Object
{
    /** @Column(type="integer") */
  protected $date;
  
    /** @Column(type="string") */
  protected $ip;
  
    /** @Column(type="string") */
  protected $query;
  
    /** @Column(type="string") */
  protected $user_agent;
}

For example, an entity for logging requests to the server, it clearly shows the essence of the problem.
If run, we get:
No identifier/primary key specified for Entity "\Entities\Request" sub class of "Data\Orm\Object". Every Entity must have an identifier/primaey.
Of course, you can add the @Id annotation to the ID and DATE fields , so that the entity would work. But this is not the right approach, if we make two requests within a second, we will get a uniqueness violation Exception. I understand that it is not possible to select a specific entity without a unique field. Purpose of record requests, and selection. No operations on a specific entry are required.
Perhaps this is a violation of ORM fundamentals, but still I wonder if this is possible without introducing an extra id column?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-05-06
@brzsmg

Of course, you can add the ID and DATE fields, the @Id annotation

Why do you need a composite primary key? ID is sufficient.
In general, by definition, an entity must have an ID, otherwise it is no longer an entity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question