Symfony2: referring foreign keys in symfony2 - symfony

This is my query to get the desired product and set its values in symfony2
$item->setProduct($id)
->setQuantity(1)
->setTemp($s1);

While using foreign keys you should use
(getReference('YourBundle:EntityName',$id)

Related

Apigee entity primary key

I have a custom entity Entity1, and I need to make it id field primary key. How to do it?
I expect that when I call mDataClient.createEntityAsync - it will update the entity if the same id already exists, currently it creates a new one.
Thanks.
Right now we do not support a primary key other than 'name' which is the default on all collections. Can you use 'name' instead of 'id'?

Symfony2: doctrine:mapping:import throws Doctrine\ORM\Mapping\MappingException - Table [...] has no primary key.

I want to import a Doctrine mapping for a table called stores. I do:
./app/console doctrine:mapping:import MyBundle annotation --filter="stores"
I get the error:
[Doctrine\ORM\Mapping\MappingException]
Table Cat_map has no primary key. Doctrine does not support reverse engineering from tables that don't have a prima
ry key.
Am I using the filter incorrectly? I dont want doctrine to try and map any table other than 'stores'
Requested create syntax:
CREATE TABLE `stores` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`storeid` int(11) NOT NULL,
`store` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=96 DEFAULT CHARSET=utf8;
Despite the --filter attribute Doctrine analyse all the tables.
If everything is OK then it go through the filter creating only the specified entity.
So, you should try to fix the cat_map table adding a primary key.
If you're not figuring out a way or if you got particular needs, please update your question including the cat_map part.
I hope this helps!
You can tell Doctrine to ignore tables that match a certain regex. For example, if you want to ignore tables that begin with "custom_", put this in your config.yml:
doctrine:
dbal:
schema_filter: /^(?!custom_)/
This seems to do the trick. For for information: http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#manual-tables
Use something other than doctrine for existing databases. Doctrine hasn't fixed this issue for many years.

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

Can I use two related objects as composite key in Doctrine bundled with Symfony2?

Object is ArticleVote and it has two related objects: User and Article. This creates user_id and article_id columns in ArticleVote table. Can I go without using "id" as an id of the table and use a composite key that consists of unique combinaiton of user_id and article_id in ArticleVote talble?
Also, is this supported in Doctrine bundled with Symfony2?
Thanks.
Yes it's support, read: http://www.doctrine-project.org/docs/orm/2.1/en/tutorials/composite-primary-keys.html

Dynamic Data Site doesn't filter by nchar field

I have 2 tables that have a foreign-key relationship through the field that has nchar type.
Database designer successfully created relationship and displays it on database diagram. But entity model created doesn't have this relationship, and as a result dynamic data site doesn't allow automated filtering by that parameter.
Is it possible to force that relationship be mapped to entity data model?
If no, how to apply filter on that field?
Dav Check if your foreign table have primary key or not. I faced same problem but after adding primary key to foreign it got resolved. Please try once.
If still you are facing problem you can use FilterUIHint annotation to do it.

Categories

Resources