In my Symfony2 repository, I’d like to get objects from a schedule table, that have started, but not finished yet. The interval, within the objects should be encountered as ‘not finished’, should be passed as a variable. Using plain SQL, it works like this: Can I achieve the same with DQL / Query Builder? This is what I have so
Tag: doctrine-orm
Select entries between dates in doctrine 2
I will go insane with this minimal error that I’m not getting fix. I want to select entries between two days, the examples below ilustrate all my fails: opt 1. $qb->where(‘e.fecha > ‘ . $…
Doctrine 2: Load entity and childs count
I have these two entities: Message entity class Message { /** * @ManyToOne(targetEntity=”User”) * @JoinColumn(name=”author”, referencedColumnName=”id_user”) */ protected $author; …
How to force Doctrine to update array type fields?
I have a Doctrine entity with array type field: /** * @ORMTable() */ class MyEntity { (…) /** * @var array $items * * @ORMColumn( type=”array” ) */ private $…
Generating next sequence value manually in Doctrine 2
What would be the easiest way to generate nextval for some particular sequence with given name? The annotation solution with specifying doesn’t satisfy me, as long as there is some more complex logic involved: in some cases I need to retrieve nextval, in other – I would go with the value retrieved from another sources (not sequence). So I hope
How to retrieve an entity with all of its associations using EntityManager in Doctrine2?
I have a simple entity with many-to-many and one-to-many associations. I’m aware of ‘Joins’ for fetching related associations which is a manual solution for my problem. How can I fetch an entity with all of its associations using EntityManager in Doctrine2? e.g.: Answer Doctrine 2 uses Proxy classes for lazy loading, so you don’t actually need to have the associations’
How persist new Entity in Doctrine 2 prePersist method?
I’ve a Entity with @HasLifecycleCallbacks for define prePersist and preUpdate method. My PrePersist method is /** * @ORMOneToMany(targetEntity=”Field”, mappedBy=”service”, cascade={“persist”}, …
Doctrine 2 + unsigned value
Is it possible to specify a column type of unsigned integer in Doctrine 2? Answer You can but you will loose portability. Use columnDefinition attribute and set it to integer unsigned. The actual code depends on what you are using. columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows
Doctrine 2: Saving Entity in Complex Relationship
I have the following relationships within my doctrine entities: FavoriteRecipe Recipe User In one of my controllers I have the following code: But this throws an exception with the following message: A new entity was found through a relationship that was not configured to cascade persist operations: EntitiesUser@00000000408bd010000000007cb1380e. Explicitly persist the new entity or configure cascading persist operations on the
How to select distinct query using symfony2 doctrine query builder?
I have this symfony code where it retrieves all the categories related to a blog section on my project: This works, but the query includes duplicates: I want to use the DISTINCT command in my query. The only examples I have seen require me to write raw SQL. I want to avoid this as much as possible as I am