How to determine order of colums in table? - symfony

I defined an Symfony2 entity class and I want to create the corresponding table in my database. This works fine thanks to the command 'php app/console doctrine:schema:update --force'.
But the order of the columns isn't equal to the order in my class. Any way to get them in the same order?

Related

Getting ids of inserted raws via doctrine dbal

I'm working on a symfony application, and i need to insert multiple raws at once, Doctrine ORM is not a good option because for each raw it will open a connection to execute the query, to avoid this and have one connection inserting all the raws i used prepared statement of doctrine dbal and it works fine, except i need to get the ids of the inserted raws, it seems the only available function is lastinsertedid which returns only the last id not all the last inserted ones, how can i achieve this?
any help would be appreciated!
This is actually not related to doctrine at all. If you want all inserted id's it must be possible in MySQL. "It's unlikely that if doctrine don't have batch insert it will support returning list of ids after batch insert :)"
Check answers related to MYSQL:
How can I Insert many rows into a MySQL table and return the new IDs?
MySQL LAST_INSERT_ID() used with multiple records INSERT statement
But it's possible in postgresql (since you didn't mention you DB):
Retrieving serial id from batch inserted rows in postgresql
You can actually generate IDs before inserting content into database. For example, using random UUIDs.
This library might be of use: https://github.com/ramsey/uuid
use Ramsey\Uuid\Uuid;
$uuid4 = Uuid::uuid4();
echo $uuid4->toString()

How correctly insert values in table using Doctrine ORM?

I use Symfony2 and Doctrine ORM. I have table "articleType" where I keep all possible article types. I need insert several values to that table only once, when table is created. My question is how and where I should do that? Because I just can't insert that values in controller with every request to that controller right? Maybe I should write down manually that inserts in Doctrine migration class?
It depends, but most of the time Doctrine Migrations are the way to go. Each migration is supposed to be applied just once and that's exactly what you need.

Extra field in manyToMany relationship

I have two tables: users and estates
A user can be "linked" to multiple estates, and an estate can be "linked" to many users. To handle this manyToMany relationship, I created a "joinTable" estatesUsers in which the primary key is actualy a composite one involving the two foreign keys userId and estateId.
This was fine until I wanted to add extra fields to this table.
I read that when adding extra fields for such a table, the relationship is not a "manyToMany" anymore but two "oneToMany" relationship instead for each original entities.
My problem is that Doctrine still not consider this table (was the join table) and skip it when I run php app/console doctrine:mapping:import AppBundle yml
How can I get the command line tool to handle correctly those relationships and generate this new entity (the yml schema files) ?
Extra question: how do I command the tool (inside the yml schema files) to create a repository class for each entity before running php app/console doctrine:generate:entities MyBundle ?
Thank you !

Symfony2.2 generate entities reversely existing one without primary key

I'm trying to reverse generate some new entities in my application using --filter option to select only the new ones.
php app/console doctrine:mapping:convert yml ./src/MyProject/MyBundle/Resources/config/doctrine/metadata/orm --filter="NewTable" --from-database --force
And I get an error message from a preexisting table, already mapped and working (actually not explicitly mapped as it is a Many to many relation table)
Table your_other_table has no primary key
My questions are:
I know Doctrine has issues generating from tables without primary key but in this case I want to ignore it with the --filter param, I don't even need an entity for this, then why do I get this error?
I usually work with own primary keys for every table, even in relation tables, I think I was "forced" to eliminate primary key in this many to many relation table in order to make relation in entities work, is this correct? Doctrine eliminates primary keys in relation tables? (I mean, they have PK but it is composed by the 2 foreign keys).

Persisting with Doctrine2 to database with REPLACE INTO instead of INSERT INTO

I have a table where I store relations between two other table with a float indicating relevance between the two rows. I have unique key on the two reference columns. The problem is, that I have to rebuild it regularly, which is kinda lengthy. So, I can't just truncate the table while I'm doing so, but I can't insert the relevance for the same row while they would be duplicates either. That's why I thought it would be great to save the current timestamp to a variable, persist the relations with REPLACE INTO instead of INSERT INTO and then remove everything created before the saved timestamp. However, I couldn't find out how. Any idea? I'm using Doctrine 2.2.0-DEV and Symfony 2.1.0-DEV.
Doctrine 2 doesn't support INSERT REPLACE or UPSERT, sorry.

Resources