Symfony2.2 generate entities reversely existing one without primary key - symfony

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).

Related

MariaDB remove foreign key to temporary table

Context:
I'm trying to upgrade a concrete5 installation from version 8.3.2 to 8.4.1. The upgrade process fails during execution of this SQL statement:
ALTER TABLE AreaLayoutsUsingPresets ADD CONSTRAINT FK_7A9049A1385521EA FOREIGN KEY (arLayoutID) REFERENCES AreaLayouts (arLayoutID) ON UPDATE CASCADE ON DELETE CASCADE
With:
SQLSTATE[HY000]: General error: 1005 Can't create table `concrete5`.`#sql-215_264a4` (errno: 121 "Duplicate key on write or update")
Investigating my database revealed that in information_schema in INNODB_SYS_FOREIGN there is the following entry:
ID FOR_NAME REF_NAME N_COLS TYPE
concrete5/FK_7A9049A1385521EA concrete5/#sql-215_26264 concrete5/AreaLayouts 1 5
Problem:
Now my understanding is, that I cannot modify the information_schema as it isn't a database but just a tabular representation of the system.
I'm wondering how do I get rid of that foreign key entry. The table concrete5/#sql-215_26264 does not exist (I can't find it on my server, nor does alter table or drop table find that table (I've tried with #mysql50# prefix and without it)). So the straight forward way of alter table to drop the foreign key fails because it can't find the table.
I guess I could mess with the upgrade script so that it creates a new foreign key ID, but I'd rather get rid of that zombie in my database. I've already tried to disable the foreign key checks, which then resulted in an error, telling me that the key cannot be added to the system tables (because it's already in there).
Reinstalling is rarely a cure for anything; but I am glad that it fixed your situation.
Table names such as #sql_... usually come from crashing in the middle of an ALTER or similar DDL. Such files can be removed. information_schema is derived from looking at the files, so I think removing the files will kill the zombie entries.
either prefix the SQL import with SET FOREIGN_KEY_CHECKS=0;
or your append it to your query ALTER TABLE...DISABLE KEYS;
... and better dump the whole database before messing around.

Can Sails.js attributes link to a collection via multiple columns?

I'm using Sails.js to build an API for an existing database. Unfortunately, modifying the structure of the database is not an option.
Many tables in the database have status columns of one type or another. They tend to have single-letter values that don't make sense without context. Context is provided by a "lookup" table in the database with 3 primary keys: table_name, column_name, and column_contents. Therefore, if I have a letter returned as a status, I can do a query against the lookup table and check a fourth column, description.
I'd love to configure my Sails.js models to understand all this, but it seems that one-to-many relationships can only be set up for tables with a single primary key. Is that correct?
Based on the "many-to-many" workaround, I assume the sails way to solve this would be to create new tables that are subsets of the "lookup" table (each for a single instance of table_name, column_name). Is there a better way?

EF6 Create one way navigation in db with two schemas

We have two tables in the same database but in different schemas.
i.e. foo.Table1 and bar.Table1 both with an Id column as primary key.
foo.Table1 is from an existing model, cannot be modified and is already in the database.
We want to create an ef6 code first model of bar.Table1 that will have its primary key (bar.Table1.Id) set as a foreign key of foo.Table1.Id. We have already accomplished it in SMSS but we cannot figure out how to do it in code without affecting foo.Table1.
Thank you

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 !

asp.net Entity Framework/ Update from database/ The table/view does not have a primary key defined and no valid primary key could be inferred

One of the database view I am trying to import using entity framework contains only two columns, one is an integer type of column and another one is an aggregate function. I am getting the following error.
The table/view does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.
I understand it is a known scenario and it can be fixed by either including a Key column in the view or modifying the edmx file manually.
I just wanted to know if there is some other solution other than the above two? I do not want to include an additional column in my query and making changes in edmx is not feasible as DB changes are very frequent and the edmx will be overwritten every time I update from db.
You can mark both properties as entity key directly in the designer but you must ensure that the composite value of these two properties will be always unique. If you cannot ensure that you must add another unique column anyway or you may have some other problems when working with such entity set.

Resources