Is there way to generate mysql schema from Yii model? In model i describe fields and relations. So it is enough to generate/update db structure.
Like symfony 2 command line:
php console/app doctrine:schema:update
No, in yii a models attributes are dynamic and come from the database. Any properties defined in the model are not attributes and therefore not in the database. For this reason if you add a new column to the post table the Post model will automatically have a magic property of that column.
What I think you're after are Migrations
Related
Is it possible to check if the relations between models are correct?
Im looking for cli command or something like Symfony2 profiler which shows wrong relations.
There is a build-in command that Validate that the mapping files are correct and in sync with the database:
./bin/doctrine help orm:validate-schema
'Validate that the mapping files are correct and in sync with the
database.'
In the symfony2 doctrine bundle exists two command instead:
doctrine:schema:validate
The doctrine:schema:validate checks the current mappings for valid
forward and reverse mappings.
and
doctrine:mapping:info
The doctrine:mapping:info shows basic information about which
entities exist and possibly if their mapping information contains
errors or not.
"Using custom column definition trigger schema update every time":
"This is a known limitation that we cannot fix."
https://github.com/doctrine/dbal/issues/2666#issuecomment-283772609
I have a SQL Server view CyclesList on the table Cycle. Cycle table contains a few columns, and CyclesList view add some more data that can be computed on database level.
And now, I have a NHibernate mapping that points to CyclesList:
<class name="Cycle" table="CyclesList">
However, I would still like to work with Cycle class, and perform Create/Update operations , but I have to use stored procedure that will access Cycle table directly. Is there a way to achieve it in NHibernate? I would appriciate a sample mapping/links to resources with samples. Thanks
You find some information in the docs under "Native-Sql -> Custom SQL for create, update and delete". Basically, you need the "sql-insert", "sql-delete" and "sql-update" elements in the mapping file.
There is also an example on Ayendes blog.
I'm having a problem with Symfony2 / Doctrine.
I'm starting to think that I'm trying to do the impossible, joining 2 seperate databases together via a relationship.
I've got a mysql database, and an sqlite database.
I've got 2 bundles (each talking to one of the databases each)
I've got 2x Entity Managers, with mappings working correctly.
I can access each database, via it's own Entity Manager just fine, Each bundle can access the other bundles Entity Manager, and it's all working well on that front.
The Sqlite database is locked-down to another application, and I have to use it as-is. The mysql-database is mine to do whatever I need with.
In the sqlite database I've got a "Projects" table
In the mysql database I've got a "Tasks" table.
One project can have many tasks.
My tasks table has a project_id field, which is populated with the ID from the projects table. What I'm trying to do is to make this relationship work properly, so that I can use twig to do what you normally can do with twig in more normal situations. I.e. call something like {{ project.tasks }} or {{ tasks.projects }}.
At the moment I've got some code in the Project controller, passing the Tasks to the views and vice versa. This does work, but it's quite cumbersome. What I'd really like to do is to have the ORM mapping working correctly between each entity.
Can Doctrine/Symfony2 do this, or am I trying to do the impossible?
Any assistance would be greatly appreciated.
Here's an extract from my config.yml file.
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: agile
entity_managers:
glue:
connection: glue
mappings:
WebplaceGlueBundle: ~
agile:
connection: agile
mappings:
WebplaceAgileBundle: ~
We have a similar problem at OpenSky: we have some data stored in MongoDB, and some stored in MySQL. We use an extension to stof's DoctrineExtensions bundle:
https://github.com/opensky/DoctrineExtensionsBundle/tree/orm2odm_references_current
This lets us add #Gedmo\ReferenceOne annotations between ODM and ORM. You might be able to use this directly between two ORM connections, but if not it'll give you a starting point for handling relationships between different persistence layers...
/**
* #Gedmo\ReferenceOne(
* type="document",
* class="MyBundle\Document\User",
* identifier="userId"
* )
*/
is there any way to update my sql 2008 db from model?
i maped model from db, and added some changes like associations and change fields name in some tables, can i update now db using my model?
Over by the solution explorer there is a model tree view. In there right click the model and there should be generate database from model.
I'm using Fluent NHibernate (and I'm a newbie). I have mapped a read-only table that already exists in the database (it's actually a view in the db). In addition, I have mapped new classes for which I want to create tables using SchemaExport.Create().
In my fluent mapping, I have specified "ReadOnly()" to mark the view as immutable. However, when I execute SchemaExport.Create(), it still tries to create the table so I get the error "There is already an object named 'vw_Existing'".
Is there a way to prevent NHibernate from trying to create that specific table?
I supposed I could export and modify the sql (SetOutputFile), but it would be nice to use SchemaExport.Create().
Thanks.
You're looking for
SchemaAction.None();