Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:50:33+00:00 2026-06-13T15:50:33+00:00

Starting out with Symfony2 + Doctrine. I have a table with User objects (fos_user),

  • 0

Starting out with Symfony2 + Doctrine.

I have a table with User objects (fos_user), for which my schema contains a roles column of an ‘array’ type.

Doctrine saves fields of this type by serializing them from php ‘array’ to ‘longtext’ (in mysql’s case).

So let’s say I have the following users saved into DB:

User1: array(ROLE_ADMIN, ROLE_CUSTOM1)
User2: array(ROLE_ADMIN, ROLE_CUSTOM2)
User3: array(ROLE_CUSTOM2)

Now in my controller I want to select all users with ROLE_ADMIN set.
Is there a way to write a DQL query which would directly return me User1 and User2?
Or do I need to fetch all users to have Doctrine to unserialize roles column and then for each of them do in_array(‘ROLE_ADMIN’, $user->getRoles())?

I have searched the DQL part of the manual, but so far did not find anything similar to my needs…

UPD: Found a question about the same thing which contains a working query code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:50:34+00:00Added an answer on June 13, 2026 at 3:50 pm

    You can simply use LIKE statement described in this manual (yes, even on serialized objects).

    I’d suggest you to create an entity class for roles and join it with the user entity by ManyToMany association.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting out with php, I have written a basic authentication script which prints out
Just starting out with subversion, have set up repos for 3 current projects and
So I am starting out on company project that will have several components: At
Starting out with Windows Azure, but how do I know which is better to
Just starting out with my first commercial app for the iStore but dont have
Just starting out on android developing. To start off, I'm building an app which
I starting out in assembla and have a code from my senior that I
Just starting out in Unix and need t workout this:- I have a csv
I'm just starting out with Facebook SSO and OpenGraph. I have SSO working with
I am starting out with OrchardCMS and have hit a road block (for me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.