I see.

Well, perhaps since my object already had an identity (by this I am 
assuming you are saying it has a unique identifier by which it is known in 
a database),
I best keep it an entity (even if it is not yet maintained under Doctrine 
facilities).

Perhaps my struggle is something else.  It is whether or not to make it 
immutable and if Doctrine works with that.
The reason immutability is just that there is no reason for the object to 
change.  And if it is indeed changed, a new one is created.
Basically what I wanted to do is to initialize the object via its 
constructor, and was not sure if Doctrine allows for me to do this.
Usually I have not used a constructor for anything when working with 
entities in Doctrine, and I don't know what Doctrine will do or what I 
should do if I do specify such a constructor.


On Friday, September 8, 2017 at 11:45:37 AM UTC-4, Maarten van Leeuwen 
wrote:
>
> I think you mix up some terminology: An object is an entity by nature if 
> it is characterized and identified by its identity. In other words: if it 
> has a primary key in the database it probably an entity and can be modelled 
> into a Doctrine Entity. 
>
> Value object ar characterized not by identity, but by value. A date or 
> datetime is characterized by value, not by identity and those cannot be 
> used as entities. 
>
>
> Regards
> Maarten van Leeuwen
>
> Op 8 sep. 2017 om 17:11 heeft Dennis Matveyev <[email protected] 
> <javascript:>> het volgende geschreven:
>
> In my code I currently have an active record implementation of a Staff 
> object.  Namely, that object self-populates at creation time, and 
> self-reloads when required.
>
> class Staff
> {
>     private $id;
>     private $name;
>     private $email;
>
>     //all the getters and setters
> }
>
> I changed the code where I pulled out database code out of it to where it 
> now populates from the outside.  One of the next steps I can take is make 
> this object into a Doctrine Entity, which is a fairly-well understood 
> concept to me (I have existing entities in my code)
> Before going that route, I thought .. what if I make it into an immutable 
> value object.  Will it benefit me?
>
> And that is my question here.  Staff is used as part of a session and 
> typically does not need to be mutable.  
> As part of making it a value object I can *remove all the setters* and *move 
> all initialization and object-loading code into the constructor*.
>
> This is where I'm struggling ...  If I do this
>
>    - can I still use the object with Doctrine?
>    - Is doing this a good idea?
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at https://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to