I am new to the ORM but already impressed about its possibilities.
When designing Facebook-like messaging system (message threads allowing multiple user chat) I have come to a problem which I don't know how to solve.
After I load the MessageThread with DocumentManager::find(...) I get the whole MessageThread object with all the messages. This might not be a good idea because of memory limitations.
So my question is whether there is a way, how to load messages dynamically, on-demand so I get the MessageThread object but when accessing the messages property, they get loaded dynamically perhaps in bundle of 50 messages?
Thank you.
These are User, Message and MessageThread classes.
Using Doctrine MongoDB ODM
class User {
/** @Id */
protected $id;
}
class Message
{
/** @Id */
protected $id;
/** @ReferenceOne(targetDocument="User") */
protected $sender;
/** @String */
protected $body;
/** @Date */
protected $sent;
/** @EmbedMany */
protected $read;
}
class MessageThread
{
/** @Id */
protected $id;
...
/** @ReferenceMany(targetDocument="User") */
protected $participants;
//Maybe EmbedMany is better in this case
/**
* @ReferenceMany(
* targetDocument="Message",
* )
*/
protected $messages;
...
}