2709 search results for Doctrine

// ... lines 1 - 2
namespace Tests\AppBundle\Controller;
use AppBundle\Entity\Subscription;
use AppBundle\Entity\User;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class WebhookControllerTest extends WebTestCase
{
private $container;
/** @var EntityManager */
private $em;
public function setUp()
{
self::bootKernel();
$this->container = self::$kernel->getContainer();
$this->em = $this->container->get('doctrine')->getManager();
}
private function createSubscription()
{
$user = new User();
$user->setEmail('fluffy'.mt_rand().'@sheep.com');
$user->setUsername('fluffy'.mt_rand());
$user->setPlainPassword('baa');
$subscription = new Subscription();
$subscription->setUser($user);
$subscription->activateSubscription(
'plan_STRIPE_TEST_ABC'.mt_rand(),
'sub_STRIPE_TEST_XYZ'.mt_rand(),
new \DateTime('+1 month')
);
$this->em->persist($user);
$this->em->persist($subscription);
$this->em->flush();
return $subscription;
}
}
See Code Block in Script
29 lines | src/Migrations/Version20180418130337.php
// ... lines 1 - 2
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180418130337 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE article ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
}
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE article DROP created_at, DROP updated_at');
}
}
See Code Block in Script
29 lines | src/Migrations/Version20180413174154.php
// ... lines 1 - 2
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180413174154 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE UNIQUE INDEX UNIQ_23A0E66989D9B62 ON article (slug)');
}
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP INDEX UNIQ_23A0E66989D9B62 ON article');
}
}
See Code Block in Script
171 lines | src/Entity/User.php
// ... lines 1 - 6
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
// ... lines 9 - 22
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 25 - 50
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: DragonTreasure::class)]
private Collection $dragonTreasures;
public function __construct()
{
$this->dragonTreasures = new ArrayCollection();
}
// ... lines 58 - 140
/**
* @return Collection<int, DragonTreasure>
*/
public function getDragonTreasures(): Collection
{
return $this->dragonTreasures;
}
public function addDragonTreasure(DragonTreasure $treasure): self
{
if (!$this->dragonTreasures->contains($treasure)) {
$this->dragonTreasures->add($treasure);
$treasure->setOwner($this);
}
return $this;
}
public function removeDragonTreasure(DragonTreasure $treasure): self
{
if ($this->dragonTreasures->removeElement($treasure)) {
// set the owning side to null (unless already changed)
if ($treasure->getOwner() === $this) {
$treasure->setOwner(null);
}
}
return $this;
}
}
See Code Block in Script
37 lines | migrations/Version20230104193724.php
// ... lines 1 - 2
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230104193724 extends AbstractMigration
{
// ... lines 15 - 19
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SEQUENCE "user_id_seq" INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE "user" (id INT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, username VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649E7927C74 ON "user" (email)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON "user" (username)');
}
// ... lines 28 - 35
}
See Code Block in Script
221 lines | src/Entity/User.php
// ... lines 1 - 5
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
// ... lines 8 - 17
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 20 - 51
/**
* @ORM\OneToMany(targetEntity=Question::class, mappedBy="owner")
*/
private $questions;
public function __construct()
{
$this->questions = new ArrayCollection();
}
// ... lines 61 - 190
/**
* @return Collection|Question[]
*/
public function getQuestions(): Collection
{
return $this->questions;
}
public function addQuestion(Question $question): self
{
if (!$this->questions->contains($question)) {
$this->questions[] = $question;
$question->setOwner($this);
}
return $this;
}
public function removeQuestion(Question $question): self
{
if ($this->questions->removeElement($question)) {
// set the owning side to null (unless already changed)
if ($question->getOwner() === $this) {
$question->setOwner(null);
}
}
return $this;
}
}
See Code Block in Script
32 lines | migrations/Version20211001172813.php
// ... lines 1 - 2
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20211001172813 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, first_name VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE user');
}
}
See Code Block in Script
Validation Auto-Mapping

... adds sensible validation constraints based off of your Doctrine metadata. The Doctrine Column annotation has a nullable option and its default value is nullable=false: In other words, the title column is required in ...

8:49
I figure out a way to fix the problem. I just installed the 1.2 version by running composer require stof/doctrine-extensions-bundle ~1.2 It may help others ;) ...
Is there easy way to do all of this with Ajax? ...i mean send form by post and use doctrine to save data to database. ...
Szymon Chomej
Szymon Chomej
Read Full Comment
Hey Pascal Q (pascal.) Yes, it still works, you can use it safely. You can find more information here: https://symfony.com/doc/current/doctrine/common_extensions.html Cheers! ...
MolloKhan
MolloKhan
Read Full Comment
After we define $plainPassword, then we can never migrate this class without Doctrine adding a plainpassword column to our User table? ...
Moises Cano
Moises Cano
Read Full Comment
Hi Ryan, A) I do have the long proxy class: EntityManager597857be7d816_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager B) I do have JMSDIExtraBundle Thanks ...
Igor Weigel
Igor Weigel
Read Full Comment
Hey Giorgio, Could you show us the line 20 in your "genus/list.html.twig" template? And the code where you use those Doctrine Criteria which caused this error? Cheers! ...
This tutorial really opened up the world of annotations for me. But, should I worry about caching? Does the doctrine annotation reader automatically cache the annotations for me? ...
thing that confused me, is i never meet a call like that to update a field... :( even i watched "go pro with doctrine" ...
Hi, how to you get code completion and color syntaxing on javascript in your twig template ? Thanks By the way this lesson about doctrine relationship is amazing ...
Do you plan to make an lessons on Doctrine 2(a project which uses pagination) ? How do you use it from plain PHP. Thank you ! ...
Hey Johan, Use the same Symfony plugin for PhpStorm - it should help with it a bit, at least it helps with doctrine query builders. Cheers! ...
we know :) - but probably most people won't. I did "sneak in" one use of "genera" in the fixtures like :) http://knpuniversity.com/screencast/symfony-doctrine/alice-faker-function ...
weaverryan
weaverryan
Read Full Comment