Hello,
Is there any way, when using Doctrine, to create a table like another? I know in MySQL there is a function to do so:
CREATE TABLE user2 LIKE user;
and tables user and user2 will be identical. Can this be done in Doctrine?
Hello,
Is there any way, when using Doctrine, to create a table like another? I know in MySQL there is a function to do so:
CREATE TABLE user2 LIKE user;
and tables user and user2 will be identical. Can this be done in Doctrine?
I imagine that what you are looking for is to define (let's use your example) on the schema level that user2
inherits from user
when your model is generated. You can do this by using doctrine's concrete inheritance which is described in the documentation.
So, in your schema.yml
:
User:
columns:
name: string
User2:
inheritance:
extends: User
type: concrete
columns:
something: int
This way user2
will be a separate table and contain the same columns ("name") as previously defined in user
. I'm not sure why you would like two identical tables, but that is most definitely possible using the above method.
I think no. :(
You can create tables from template like here http://www.doctrine-project.org/documentation/cookbook/1_1/en/plug-and-play-schema-information-with-templates or use Doctrine_RawSql.
Doctrine provides a simple method for this: Doctrine_Record::copy().
$copy = $user->copy();
Notice that copying the record with copy() returns a new record (state TDIRTY) with the values of the old record, and it copies the relations of that record. If you do not want to copy the relations too, you need to use copy(false).
Get a copy of user without the relations
$copy = $user->copy(false);