Fixing Doctrine Segfaults

I had a tricky segfault when trying to save a very simple Doctrine object. Here’s my debugging process and solution. Context I was using the sabre/vobject package to parse and save some iCal data. The parsed data was assigned to properties of a Doctrine entity and then persisted. The segmentation fault was happening every single time I called the…

Read More

Forcing Doctrine to Persist

I stumbled upon a case where Doctrine would refuse to persist my entity due to a very special circumstance. Here’s the context: I’m using a generic method in my Repository to fetch a Post. I’m selecting partial fields like this:

If the entity is found, then I proceed to delete it by setting is_deleted to true,…

Read More

Doctrine not saving ManyToMany

Say you have a ManyToMany relationship, like Post <—> Tag.

When you add tags to a Post and the save the Post, everything is great. But when you add posts to a Tag and then save the Tag, the posts are not saved. Why? Because Doctrine persists changes only on the owning side of a relation. The owning side is…

Read More

Reduce number of queries

Customers often call me because their site is slow. One of the most common problems I found was a high number of queries that get executed for every single page hit. When I say a lot, I mean sometimes more than 1000 queries for a single page. This is often the case with a CMS…

Read More

Doctrine: saving you some tables and headaches

I like database schema normalization, but sometimes it just creates too much overhead. For example, you may want to let your users to enter a number of URLs (facebook, linkedin, twitter, blog, company, etc.) The straightforward solution seems to add a Url table with foreign key (user_id=1) to link it to the User. Sometimes you want…

Read More