Skip to content

Instantly share code, notes, and snippets.

What's the difference between cascade="remove" and orphanRemoval=true in Doctrine 2

TLDR: The cascade={"remove"} is like a "software" onDelete="CASCADE", and will remove objects from the database only when an explicit call to $em->remove() occurs. Thus, it could result in more than one object being deleted. orphanRemoval can remove objects from the database even if there was no explicit call to ->remove().

I answered this question a few times to different people so I will try to sum things up in this Gist.

Let's take two entities A and B as an example. I will use a OneToOne relationship in this example but it works exactly the same with OneToMany relationships.

class A
@dpalomar
dpalomar / .gitattributes
Created April 8, 2016 12:43
Fixing CRLF with gitattributes
From this [issue](https://github.com/puphpet/puphpet/issues/1025#issuecomment-157059174):
I know that this issue is closed, but as I spent a lot of time to understand what was going on, I made some researches and I can explain why this happen, and you can fix it.
Using git config core.autocrlf true can help, but not on a multi-developpers project.
This command has to be the same on each developper machine, and that's not always the case.
You have to use the .gitattributes provided in the puphpet archive and edit it as follow (carefull, this file need to be in your project root)
You also need to use an IDE that allow you to save/edit files as LF (like phpstorm). You can check the type of the file in the bottom right corner, in the status bar (you'll see LF or CRLF while a file is opened)
@fesor
fesor / README.md
Last active July 22, 2023 23:00
Symfony Request Object

Symfony Request Object

This is proof-of-concept implementation of laravel's like form requests.

Rational

Most of Symfony developers uses forms to map request data to some Data Transfer Object. This object then passes to validator and system start to work with validated data converted to be compatible with application model.

@zmts
zmts / tokens.md
Last active May 4, 2024 17:22
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
[In reply to Moroshka]
Распишу по буквам, потом в совокупности
S - (SRP):
https://www.youtube.com/watch?v=AEnePs2Evg0
https://goo.gl/LatDmF (link wikipedia)
O - (Open/closed):
https://www.youtube.com/watch?v=DJF_sGOs2V4
https://goo.gl/6p3jfY (link wikipedia)
L - (Liskov):
https://www.youtube.com/watch?v=bVwZquRH1Vk
@hurricane-voronin
hurricane-voronin / README.md
Last active May 2, 2024 08:20
Naming Classes Without a 'Manager'
@esilvajr
esilvajr / image_phpstorm_server.png
Last active March 27, 2022 23:49
How to use XDebug inside a docker container.
image_phpstorm_server.png
@me7media
me7media / PHPSTORM XDEBUG ubuntu NGINX php7.2-fpm
Created October 10, 2018 15:02
PHPSTORM XDEBUG ubuntu NGINX php7.2-fpm
sudo apt install php7.2-xdebug
sudo find / -name 'xdebug.so'
sudo gedit /etc/php/7.2/fpm/php.ini
sudo gedit /etc/php/7.2/cli/php.ini
sudo gedit /etc/php/7.2/cli/conf.d/20-xdebug.ini
[Xdebug]
; путь к файлу so, который мы временно сохаринили на шаге раньше
zend_extension=/usr/lib/php/20170718/xdebug.so
; остальные обязательные параметры
xdebug.profiler_enable_trigger=1
@luismts
luismts / GitCommitBestPractices.md
Last active May 3, 2024 11:06
Git Tips and Git Commit Best Practices

Git Commit Best Practices

Basic Rules

Commit Related Changes

A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits. Small commits make it easier for other developers to understand the changes and roll them back if something went wrong. With tools like the staging area and the ability to stage only parts of a file, Git makes it easy to create very granular commits.

Commit Often

Committing often keeps your commits small and, again, helps you commit only related changes. Moreover, it allows you to share your code more frequently with others. That way it‘s easier for everyone to integrate changes regularly and avoid having merge conflicts. Having large commits and sharing them infrequently, in contrast, makes it hard to solve conflicts.

Learning Plan for Design Patterns and Principles of Good Design

These learning resources primarily focus on programming using Good Design Principles and Design Patterns

  • There is an emphasis on learning using PHP, although most patterns are universal to every object orientated language.