Symfony 4: Doctrine

Symfony 4: Doctrine

The Dangers of CASCADE in Doctrine Entities

You can mix both Doctrine and SQL cascading using the on-delete and on-update properties of the element. The SQL cascade policy will act first, thus allowing for fewer queries.

  • SQL Cascade:

    • done via join-column on child
    • put on child table (rooms)
    • defaults: nullable=true
  • Doctrine Cascade:

    • done via: cascade-remove on parent
    • put on parent entity’s definition (abstract rooms)

Kada je nullable u pitanju:

  • radi: @ORM\Column(…, nullable=true)
  • ništa ne radi: @ORM\JoinColumn(nullable=true) ustvari radi, sali SAMO kada je relation: tada je default true, a radi: @ORM\JoinColumn(nullable=false)

  • Da sredim pipeline malo? zbog env variabli i prelazak na merge request?
  • Zašto koristimo key u trans, a ne baš engleski tekst (source of translation)? Zato što nas mrzi da kucamo i sve inače izgleda ružno zato.

PHP Translation — PHP Translation 1.0.0 documentation

Goodle: Automatically Translate

Eat shit: Translation keys https://php-translation.readthedocs.io/en/latest/best-practice/index.html#translation-keys

Using Real or Keyword Messages? https://symfony.com/doc/current/components/translation/usage.html#creating-translations

php-translation/symfony-bundle: Symfony integration for Translations


How to find out which translation is missing or which one is unused?

… by typing php bin/console debug:translation de. »

How to update XLF translation file with new keys from PHP & Twig templates?

translation:update command is a great way to extract translation messages and keep them up to date. It’s possible to write your own extractors and add them to the chain.

By issuing: »

# just display
php bin/console translation:update en --dump-messages 

# write to 
php bin/console translation:update en --force

How to access Translation UI?

Simply by visiting: http://127.0.0.1:8000/admin/_trans


Automatic translation


collection of forms

Using the new OneToMany Collections > Doctrine Collections: ManyToMany, Forms & other Complex Relations | SymfonyCasts

How to Embed a Collection of Forms (Symfony Docs)

Easy Edit Form > Symfony 3 Forms: Build, Render & Conquer! | SymfonyCasts

IMPORTANT by_reference CollectionType Field (Symfony Docs)


cascaded collection, save?

Doctrine Cascade Options for OneToMany - Stack Overflow Adding to a Collection: Cascade Persist > Doctrine Collections: ManyToMany, Forms & other Complex Relations | SymfonyCasts

Working with Associations - Doctrine Object Relational Mapper (ORM)

https://stackoverflow.com/questions/48130633/symfony3-saving-a-collection


Sample data:

php bin/console doctrine:fixtures:load –group=samples –append

You should run that in loop. To get 10 times, type:

# powershell in windows
for ($i=0; $i -le 10; $i++) { iex "php bin/console doctrine:fixtures:load --group=samples --append" }

# bash in linux
for ((i=1; i<=10; i++)); do php bin/console doctrine:fixtures:load --group=samples --append; done 

improve that with faker


@Datatable

  • scopes are just where this will be displayed. If not specified, everywhere. Resident: Datatable(title=“rentalObject”, field=“name”, width=255, scopes = { “portfolio”, “property” }, order=3)

  • hasFilter, filerLabels, filterValues, filterKey Resident - filtering one key (delectable, above datatable) @Datatable(title=“type”, width=150, order=4, hasFilter=true, filterLabels={“Privatperson”, “Firma”}, filterValues={ 1, 2 }, filterKey=“residentType”)


TEST

    - cp .env.test .env
    - php bin/console doctrine:database:create -e test
    - php bin/console make:migration -e test
    - php bin/console doctrine:fixture:load -no-interaction -e test
    - php composer.phar test

DEPLOY

script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

php -d memory_limit=-1 C:\Users\cvladan\scoop\apps\composer\1.9.0\composer.phar i


To solve error “Cannot delete or update a parent row: a foreign key constraint fails” add annotation to “child” entity field, also known as the “Many” side of any OneToMany or ManyToOne relation as this is where database generates Foreign keys.

@ORM\JoinColumn(nullable=true, onDelete="SET NULL")

About Referential Actions (ON DELETE AND ON UPDATE) in MySQL:

  1. RESTRICT (default)
    RESTRICT means that any attempt to delete or update the parent will fail throwing an error. This is the default behavior

  2. CASCADE

    • ON DELETE CASCADE means that if the parent record is deleted, any child records are also deleted. This is not a good idea in my opinion. You should keep track of all data that’s ever been in a database, although this can be done using TRIGGERs
    • ON UPDATE CASCADE means that if the parent primary key is changed, the child value will also change to reflect that. Again in my opinion, not a great idea. If you’re changing PRIMARY KEYs there is something wrong with your design.
  3. NO ACTION In MySQL, equivalent to RESTRICT

  4. SET DEFAULT In MySQL, equivalent to RESTRICT

  5. SET NULL Delete or update the row from the parent table, and set the foreign key column or columns in the child table to NULL.

Basic Mapping - Doctrine Object Relational Mapper (ORM)

innodb - Difference between On Delete Cascade & On Update Cascade in mysql - Database Administrators Stack Exchange doctrine2-cascade-orphanremoval-difference.md The Dangers of CASCADE in Doctrine Entities inanzzz | One to many association cascade example with doctrine annotations php - On delete cascade with doctrine2 - Stack Overflow

symfony - Symfony2 + Doctrine2 onDelete=“restrict” - Stack Overflow zend framework - Want NO ACTION on delete and NO ACTION on update on doctrine 2 ORM - Stack Overflow php - On delete cascade with doctrine2 - Stack Overflow https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/annotations-reference.html#annref_joincolumn Working with Associations - Doctrine Object Relational Mapper (ORM)


symfony - Doctrine schema update or Doctrine migrations - Stack Overflow


https://avxhm.se/ebooks/Git-Essential-Training-Branches-Merges-Remotes-REVISION-2019-Q2.html https://avxhm.se/ebooks/naag30373.html https://avxhm.se/ebooks/master-the-kraken-gitkraken-in-2019.html


  • Autowiring is when you type-hint via __construct and that’s available everywhere later-on

  • Container holds services (and config) / php bin/console debug:container

  • Config Parameters are variables in config / php bin/console debug:container --pareameters

  • What’s the difference between Controller or AbstractController? Not much: both are identical, except that AbstractController is more restrictive: it does not allow you to access services directly via $this->get() or $this->container->get().


    Uopšte nisam ni siguran da li Fairwalter koristi: Symfony DataTables Bundle - ma jok!


CI/CD essentials from scratch with Gitlab. - Faun - Medium

Configure monolog to use error_log - Deploy a Symfony application - Clever Cloud Documentation


Jebena agonija Symfony Tutorial: Building a Blog (Part 1) Get Started with Symfony 4 - Mouna Ben Hmida - Medium


Nauči PHPStorm A Guide to Using PHPStorm to its Fullest | Toptal Top 20 Navigation Features in IntelliJ IDEA - Andrey Cheptsov - Medium


koji će mi kurac JSON with MariaDB Platform: What Is JSON and Why Use It – With Examples | MariaDB


PHP_INI_SCAN_DIR C:\Users\cvladan\scoop\apps\php\current\cli;C:\Users\cvladan\scoop\apps\php\current\cli\conf.d;


Export routes to JSON

When adding functionality to Command needed for edit/delete in datatable:

When using Webpack and Encore to package assets, we need to use the dump command and export routes to json. @see: https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html

php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

composer config -g github-oauth.github.com 0824f75d4b5298731ba2f056ba63ac317dc1b17c

Pravi account je (sa dosta podataka): mueller@fairwalter.ch / demo Bezbedni, gde mogu da drndam sve: testvladan@fairwalter.ch / vladan

date 01. Jan 0001 | modified 10. Jun 2024
filename: Temp » Symfony & Doctrine