Closed tonymillion closed 12 years ago
That is correct operation. Your first attempt fails because you are comparing complex objects that are not the same. The second one works because you are comparing id objects which would be converted to a string during comparison. If you'd like to do the comparison as you did in your first attempt just add a toString method on your user object to return the same thing as a toString on id. eg
public function __toString() { $this->getId()->toString(); }
On Fri, Dec 23, 2011 at 5:16 AM, Tony Million reply@reply.github.com wrote:
I have a blog system with 'User' objects. Users can either post or comment. A poster can comment on their own post.
In both posts and comments I have
class Comment extends Shanty_Mongo_Document { protected static $_requirements = array( 'user' => array('Document:User', 'AsReference'), class Post extends Shanty_Mongo_Document { protected static $_requirements = array( 'user' => array('Document:User', 'AsReference'), 'comments' => 'DocumentSet', 'comments.$' => 'Document:Comment',
in my code I was coding a system that sends a notification to the writer of a Post and to all the Commenters on a Post. Obviously if a poster has commented on their post I don't want them getting two notifications so I did something like:
foreach($post->comments as $comment) { if($post->user == $comment->user)
however the comparison fails … if I do
if($post->user->getID() == $comment->user->getID())
it succeeds.
Is this correct operation? Am I doing something wrong?
Reply to this email directly or view it on GitHub: https://github.com/coen-hyde/Shanty-Mongo/issues/58
I have a blog system with 'User' objects. Users can either post or comment. A poster can comment on their own post.
In both posts and comments I have
in my code I was coding a system that sends a notification to the writer of a Post and to all the Commenters on a Post. Obviously if a poster has commented on their post I don't want them getting two notifications so I did something like:
however the comparison fails … if I do
it succeeds.
Is this correct operation? Am I doing something wrong?