Answer the question
In order to leave comments, you need to log in
Why doesn't the one-to-many relationship work?
Goodnight.
There is a `limits` table and a `limits_params` table.
CREATE TABLE limits(
id INT AUTO_INCREMENT NOT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB;
CREATE TABLE limits_params(
id INT AUTO_INCREMENT NOT NULL,
limit_id INT DEFAULT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB;
ALTER TABLE `limits_params` ADD CONSTRAINT fk_limit_id FOREIGN KEY (`limit_id`) REFERENCES `limits` (id)
/**
* @ORM\Entity(repositoryClass="App\Repository\LimitsRepository")
*/
class Limits
{
/**
* @ORM\OneToMany(targetEntity="App\Entity\LimitParams", mappedBy="limit", cascade={"persist"})
*/
private $params;
public function __construct() {
$this->params = new ArrayCollection();
}
public function getParams()
{
return $this->params;
}
}
/**
* @ORM\Entity(repositoryClass="App\Repository\LimitParamsRepository")
* @ORM\Table(name="limits_params")
*/
class LimitParams
{
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Limits", inversedBy="params", cascade={"persist"})
* @ORM\JoinColumn(name="limit_id", referencedColumnName="id")
*/
private $limit;
}
Answer the question
In order to leave comments, you need to log in
The doctrine "lazily" loads collections. This means that the results will be only when explicitly accessed, that is, when iterating and accessing properties.
For "greedy" loading in the config (in your case, the annotation), you need to write eager = "fetch", then the collection will be initialized immediately
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question