Domanda

I have database table with 7 rows, I'am trying to fetch those rows with findAll function

$machine_current_counter_repo = $this->getDoctrine()->getRepository('DummyMonitorBundle:MachineCurrentCounter');

$counters = $machine_current_counter_repo->findAll();

The result is 7 rows, but all rows contain data from the first row.

Here is database table entity.

And table structure:

`machine_current_counter` (
  `machine_id` tinyint(3) unsigned NOT NULL,
  `counter_value` int(10) unsigned NOT NULL,
  `time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`machine_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

What could cause this problem?

Ps. Entity is generated from database so by default first column setup was this (not sure why type was "boolean", but I changes it to integer, still that didn't solved the problem):

/**
 * @var boolean
 *
 * @ORM\Column(name="machine_id", type="boolean")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $machineId;
È stato utile?

Soluzione

@ORM\Id means values of this field MUST be unique. With the boolean type they can be unique only in 2 or less row (because boolean has only 2 values - 0 and 1). I think you have logical mistake, and must simply change type of field to integer. Like that:

/**
 * @var integer
 *
 * @ORM\Column(name="machine_id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $machineId;

Then update your schema by ./app/console doctrine:schema:update then recreate data into table.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top