Skip to content

Initial Entity and Fixtures#3

Merged
taleksey merged 3 commits intomainfrom
fill-data-and-create-main-page
Dec 28, 2021
Merged

Initial Entity and Fixtures#3
taleksey merged 3 commits intomainfrom
fill-data-and-create-main-page

Conversation

@taleksey
Copy link
Owner

No description provided.

*/
private $customerType;

public function __construct()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в 8.1 не уверен слопает ли доктрина но можно уже так

    public function __construct(
        private State $state = new InitialState(),
    ) {
    }

https://stitcher.io/blog/php-81-new-in-initializers

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут есть один вопрос, смотри у меня получается что идет как раз связка
`
/**
* @var Collection
*/
#[ORM\OneToMany(mappedBy: "customer", targetEntity: "Quiz")]
private Collection $quiz;

public function __construct()
{
$this->quiz = new ArrayCollection();
}

`
Но если я сделаю короткую инициализацию как я смогу тогда написать #[ORM\OneToMany(mappedBy: "customer", targetEntity: "Quiz")]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В последних версиях должны были добавить возможность писать, проверь если взлетит то ок, нет то оставляй как есть )

public function __construct(
    #[ORM\Column(type: 'string')]
    private string $firstName,
    ...
) { }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я написал такую вещь,
public function __construct( #[ORM\OneToMany(mappedBy: "quiz", targetEntity: "Question")] private ArrayCollection $questions, ) { }
Но получил вот такую ошибку при попытке добавить фикстуры:
Too few arguments to function App\Domain\Quiz\Entity\Quiz::__construct(), 0 passed in /srv/app/src/Infractructure/DataFixtures/QuizFixtures.php on line 23 and exactly 1 ex pected
Я поискал в гите в репизотории орм и нашел переписку об этом doctrine/orm#8430
Но правда, этот вопрос остался открытым.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ок, оставляй как было - вроде закрыто doctrine/orm#8266 но либо не релизнулось либо еще в планах, четкого ответа нет - ссылки на эту ишью и она вроде вмержена

/**
* @ORM\PrePersist
*/
public function setCreatedAtAutomatically()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:void ?


use Doctrine\ORM\Mapping as ORM;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

т.к. используешь php 8 можно попробовать использовать атрибуты (большинство библиотек уже готовы)

@taleksey taleksey merged commit f72728c into main Dec 28, 2021
@taleksey taleksey deleted the fill-data-and-create-main-page branch December 28, 2021 17:06
@taleksey taleksey restored the fill-data-and-create-main-page branch December 28, 2021 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments