Doctrine many-to-one scalar

Viewed 43

Is there a way that I can create a many-to-one relationship that looks and feels like a JSON array? I have a User entity that has "dates" associated with it. I want my serialized entity to look like this:

{
    id: 1,
    name: "Josh Doe",
    age: 25,
    dates: ["2021-08-11", "2021-08-12", "2021-08-31"]
}

I know I can create a JSON column, however, I thought it would be more efficient having a separate table as I am frequently querying by a specific date.

user_id    date
1          2021-08-11
1          2021-08-12

However, when I create a standard many-to-one relationship, I do not get an array for "dates", rather I get an array of objects. Furthermore, when I denormalize data to update the User entity, I cannot provide an array of dates, I need to provide an array of objects.

Is there a way I can simply this and have the many-to-one act as an array? Alternativly, is JSON array less efficient ?

0 Answers
Related