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

  • SEARCH
  • Home
  • 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 8123079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:03:31+00:00 2026-06-06T06:03:31+00:00

The Problem: I am working on a WordPress Symfony bundle and creating entities for

  • 0

The Problem:

I am working on a WordPress Symfony bundle and creating entities for it.

I have a Comment entity, and $comment->user is mapped to an User entity.

However WordPress use 0 to represent a guest user. It cause a lots of problems in Doctrine because the user with id zero never exist. It cause the following issues:

  • $comment->getUser() might throw an entity not found exception when the row’s user_id is 0.
  • $comment->setUser() doesn’t work because you can not use null to repensent guest (should use 0), and you cannot use new User(0) neither.

The Question:

By default, the following code would save null to user_id column in database:

$comment->setUser(null);

Is it possible to make Doctrine save 0 (instead of null) to the user_id column?

Or even better, can I interchange 0 and null when dealing with the user_id column?

Thank you for your time.

Test Cases:

// if a guest posted a comment, pass null to setUser()
// although the actual value will be saved to user_id column is 0
$guestComment->setUser(null);

// if a comment was posted by a guest, getUser() should return null
// although the actual value returned by user_id column is 0
$guestComment->getUser(); // return null

// if a member posted a comment, pass a User entity to setUser()
$memberComment->setUser(new User());

// if a comment was posted by a member, getUser() should return the User entity
$guestComment->getUser(); // return User entity.

Direction:

I am looking at creating a custom mapping types
http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html

  • 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-06T06:03:33+00:00Added an answer on June 6, 2026 at 6:03 am

    I turn out fixed the problem by creating a custom type:

    https://github.com/kayue/WordpressBundle/blob/master/Types/WordPressIdType.php

    <?php
    
    /**
     * Datatype for WordPress's IDs
     *
     * WordPress use 0 to represent a guest user. It cause a lots of problems
     * in Doctrine because the user with id zero never exist. This datatype
     * convert 0 to null, make life easier.
     */
    
    namespace Hypebeast\WordpressBundle\Types;
    
    use Doctrine\DBAL\Types\Type;
    use Doctrine\DBAL\Types\BigIntType;
    use Doctrine\DBAL\Platforms\AbstractPlatform;
    
    class WordPressIdType extends BigIntType
    {
        const NAME = 'wordpressid';
    
        public function convertToPHPValue($value, AbstractPlatform $platform)
        {
            if($value === 0) {
                return null;
            }
    
            return $value;
        }
    
        public function convertToDatabaseValue($value, AbstractPlatform $platform)
        {
            if($value === null) {
                return 0;
            }
    
            return $value;
        }
    
        public function getName()
        {
            return self::NAME;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a wordpress theme and I have a little problem
I am currently working on a Wordpress blog installation. Problem i am facing is
I had a problem working with the image classes in java. I am creating
I have a strange problem working with HTML,CSS in different browsers: Firefox 3.6 and
I have a small problem when im working with a menu and a list
I am currently working on Problem 62 I have tried the following code to
i'm having a little problem. I'm working on a wordpress template which lists all
I am facing quite a strange problem at the moment, I have wordpress and
I'm trying to make a page for use with wordpress and it's almost working,
So I have been working with Wordpress 3.x and trying to build a custom

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.