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 8503765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:50:47+00:00 2026-06-11T01:50:47+00:00

I have a document with a field marked for persistence as a Collection use

  • 0

I have a document with a field marked for persistence as a Collection

 use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;  

/** @ODM\Document */
class Item
{
    /**
    * @ODM\Collection
    */
    protected $things;

}

By default, when Doctrine maps the values from Mongo it will set $things to be an instance of Doctrine\Common\Collections\ArrayCollection.

This violates my domain model however as my domain objects expect the $things property to be an instance of my own collection class ThingsCollection. This class does various validations on the list of things.

How can I tell Doctrine to use my ThingsCollection class instead? I imagine I will have to make the ThingsCollection class implement the Doctrine\Common\Collections\Collection interface but that is not a problem if I can just figure out how to tell Doctrine about the mapping in the first place.

  • 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-11T01:50:48+00:00Added an answer on June 11, 2026 at 1:50 am

    The answer is that it is not possible.

    Furthermore, despite the documentation being confusing and saying otherwise, for a general Collection property mapping as above (not a reference) an ArrayCollection is not returned. A basic php array is given.

    So, it appears in this situation, you are forced to work with arrays, at least currently.

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

Sidebar

Related Questions

I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have the following: class Email include ::Mongoid::Timestamps include ::Mongoid::Document field :email_address, :type =>
In MongoDB, I have a document with a field called ClockInTime that was imported
I have the following models class Track include Mongoid::Document field :artist, type: String field
I have two models, Category and Post. Category.rb class Category include Mongoid::Document field :title,
I have a author model class Author include Mongoid::Document field :name end In My
I have a Mongoid model that looks like this: class V1Cache include Mongoid::Document field
If I have a model... class Post include Mongoid::Document field :link field :title field

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.