Hello I'm learning Symfony 3 and i Have this problem that I have an Entity Projects and an entity ProjectImages and relations is one to many.
Now I want to add f.e 4 images to one project and I don't know how to do it.
I read the documentation, how to add files etc. But how to add file in association in one FOrm where I create project ?
You should use form collection here is examples.
http://symfony.com/doc/current/cookbook/form/form_collections.html
Related
First of all, I apologize for my little knowledge of the sector, but I am new to Symfony and PHP.
I am doing a new project using Symfony 4 and the following problem arises.
I have two tables in my application, one for Contracting and another for Alerts.
They are related to each other through an intermediate table, since a contract can have several alerts at the same time.
I leave an image so you can see the relationship.
I already have all the entities created with their Setters and Getters and all the forms made and working, to add a new alert and a new contract and all the additional functionality.
My purpose is to program a function, so that in the intermediate table are stored the IDs of contracts and alerts and are related to each other so that later I can show a list of contracts with their respective alerts.
I can not create the logic to collect the contract ID and the ID of the alert and save it in the table that relates them and then shows it.
I do not know if I've explained myself correctly or if I say some nonsense, excuse me.
First of all, please read the Doctrine2 Many-to-Many docs carefully.
After proper relations configuration creating relations with Doctrine will be as easy as:
$contact->addAllert($alert);
With proper flushing if you don't have cascade: persist configured.
You don't have to take care about the joining table - Doctrine2 will take care of it for you.
Running: Laravel 5.3 with Laravel Backpack CRUD 3.1
I am running into situations where I have a Model that I would like to add multiple related (child) records too, using just one CRUD form. Some examples would include adding multiple files... but let's start small. I have found the following posts that have similar topics, but not clear answer on the best way to do this.
Is the best way to use the table Field Type? https://laravel-backpack.readme.io/docs/crud-fields#section-table But, I guess the drawback is not having validation on the child records?
A similar tutorial to this one would be cool: https://backpackforlaravel.com/articles/tutorials/nested-resources-in-backpack-crud
So, an example would be where I have a Journey model and would like to add multiple Chapters to the Journey directly on the same Journey CRUD form.
Let me know if this question makes sense... and any suggestions/advice you can share.
Backpack doesn't support adding more entities in one form - every such form is very different.
My recommendation would be to edit the EntityCrudController::store() and EntityCrudController::update() methods, to check for the values of the "table" field and add/update/remove connected entries.
I'm using Zend Framework 2 with Doctrine.
I have two entities with ManyToMany relations, Portfolio and Tag.
When I'm editing Portfolio, I use select2 and I have possibility to not only select existing Tags, but also create new Tag from text input.
Can someone give me advice how to implement creation of new Tag? Seems like this case (zf2, doctrine, select2) is typical. Is there built-in methods to create new entities?
Logically Many to Many relationships should be resolved into One to Many with a new table.
if you can post your table schema I will create you the complete model/entity.
Currently I'm working on doctrine module for favorites which can be reusable in any project and for any entity.
However there is problem with JOINs. I followed this article about dynamic mappings and it works great.. Well almost.
I've got User, Article and FavoriteItem entities, where Article entity can be added to favorites. Probably link to that github project with readme would be better (link).
The problem is mainly in that method which should return FavoriteItem by User and IFavoritableEntity, which in our example will be Article. As you can see, that method uses native query, but is it possible to use DQL? I know that I would have to use join to table without association, but it seems that doctrine can do that just for one-to-many/many-to-one associations.. I'm right? Or is there any other way how to do that in DQL?
Also do you think there is any way at all how to select in one query (DQL) all IFavoritableEntities by one User? I just can't imagine any.
Thank you
So I found other option which is add possibility to extend FavoriteItem entity where I'm able to add field with association to eg. Article::favorites field.
I have two entities related with many to one relation but each one belongs to a bundle.
When forcing the update in the database I get the following error
the target -entity cannot xxxx\Bundle1\Entity be found in xxxx\bundle2\entity
Any ideas please??
Just create an entity extending xxxx\Bundle1\Entity in your xxxx\bundle2 and make the relationship between two xxxx\bundle2 entities.