Hello all,

I have a project that has been written under Doctrine 1.2 and contains 80+ 
tables. Since a long time now I'm trying to figure out how I could port the 
old paradigm but from what I read it is more than just "change" the methods 
and migrate the entity format.

I have some question that I couldn't clarify on the behavior of the new 
engine (sorry if I can't locate whether it's on DB or ORM layer).


1- Using R/O objects

Currently (1.2) I can fetch object either in R/O or as Entities, the 
business logic is not aware of that and just read with brackets [] or set 
with arrows ->. This style approach allows me to clearly distinguate if I 
want to alter or just query the data. The bracket is available on both 
formats, whereas the arrow is not possible on R/O objects as they are 
fetched as plain php arrays for performance reasons, so if by error some 
code tries to change it, since it will use the arrow it will throw an 
error. 

Example (in my code the doctrine entities are called Dao):

class Dao_Something extends Doctrine_Record
{
    // ...
}

class Something
{
    protected $_dao;

    public function getId() { return $this->_dao['id']; }
    public function getValue() { return $this->_dao['value']; }
    public function setValue($v) { $this->_dao->value = $v; }

    public function __construct($dao)
    {
        $this->_dao = $dao;
    }

    public function save()
    {
        if (!$this->_dao instanceof Dao_Something)
        {
            throw new Exception('Read only object');
        }
        $this->_dao->save();
    }

    public static function find($id, $readOnly = true)
    {
        $dao = Dao_Something::find($id, $readOnly);
        return new Something($dao);
    }
}

Yes, I know, sounds like a lame parachute but it was how I learned Doctrine 
from a friend 5 years ago and the project is from 2012.

I tried to search about R/O objects with the new Doctrine but saw that new 
entity system forces accessors like ->get, ->setXXX, no brackets anymore. 
That means that I cannot fetch R/O, even for queries I will have to get 
read-write objects, which is a concern for me as some code may accidentally 
write to it and the entity will track it ...

Is there a way to protect from accidental writes without having to make the 
business code aware of the nature of the object, or do I have to create 
some flag inside all my classes to tell that I'm R/O ? What about the 
performances ? I have a lot of relations that I have to fetch, arrays in 
Doctrine 1.2 are /much/ faster than populated objects, so that worries me 
even for Doctrine 2.


2- Behavior of persist()

Currently when I want to save on database, the business logic call 
Entity->save(). If it is not called, even if we got a R/W object, it won't 
be written on database.

If I understand well with Doctrine 2 as soon as you modify an entity it is 
tracked so the flush() will write its changes. I'm concerned because that 
means that you lose control and if there's some "wild" code somewhere it 
could cause data to be written and it could be very difficult to track down 
the culprit.

Is there a way to disable this behavior, or is there mitigation possible ?


3- Transactions

As I understand, Doctrine does logic transaction and not at DB level, does 
that mean that we have to bypass the ORM and use the DBAL to make "true" 
transactions if needed ? I use MySQL and sometimes I have to write up to 20 
records in a flow.

I'd like to know also if the flush() does automatic transaction commit or 
if it is independant. In case of revert, in Doctrine 1.2 the Database was 
left intact but the objects were still pending, is it the same in Doctrine 
2 ? This last is not so important as typically after an error the 
controller exits anyway.


Thanks in advance for your feedback, these questions are very important to 
me in order to figure out if I can eventually migrate or if I have to cope 
with the former framework because of stall code and/or too much 
dependencies on the old system.

Sylvain T.

-- 
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 http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to