One to many rel in GAE using G data Store Entity - google-cloud-datastore

I want to create one to many relation using Google DataStore entities Something like:
Entity proj=new Entity("Project");
proj.setProperty("name","Project 1");
Now I want to associated multiple user entities with this project
Entity user1= new Entity("User");
user1.setProperty("name", "User1");
Entity user2= new Entity("User");
user2.setProperty("name","user2");
How do I associate multiple users 1&2 to same Project proj?

Set the project reference on the user entity

Related

Edit Symfony entity from the frontend

I have a Symfony app using multiple entities.
A third-party analytic tool plugs to my database to create reportings.
What I would like to achieve, is being able to update the Symfony entity from the frontend in order to add new fields to the database tables (in order to get the new fields showing up in the reporting tool).
Anyone has a idea on how to achieve that?
Thanks in advance.
If i understand correctly, you wan't to be able to add fields to your entity dynamicaly.
I don't know if this is doable and if so, it would probably be messy and unsecure.
What you can do however is using sub-entities with dynamic key => values fields.
You should have one main entity, an entity with the list of your dynamic fields, a many to many relation between your main entity and your fields entities and a third entity with the actual values from those fields.

Symfony clone an entity from one entity manager to another with FosUser

I want to copy data from one database to another. I get two Customers from two different entity managers (emLocal,emRemote).
The customer entity is in a oneToOne relationship with FosUser
The flush try to insert a blank user. even if I try to detach concerned entities and set every relation to null.
I read from github that FosUserBundle is not designed to works with two entity manager
$remoteCustomer = $order->getCustomer();
$onlineCustomer = $this->emLocal->getRepository("LilWorksStoreBundle:Customer")->findOneBy(array("remoteUser"=>$remoteCustomer->getUser()->getId()));
if(!$onlineCustomer){
$onlineCustomer = clone $remoteCustomer;
}
$this->emLocal->detach($onlineCustomer->getUser());
$onlineCustomer->getUser()->setCustomer(null);
$onlineCustomer->setUser(null);
$this->emLocal->persist($onlineCustomer);
$this->emLocal->flush();
How I can prevent this INSERT?
I believe you should use another Entity Manager to save $onlineCustomer.
$this->emOnline->persist($onlineCustomer);
$this->emOnline->flush();

Entity for table not managed by Doctrine?

So I'm using Symfony 2 with Doctrine 2 for a new web application but we have a few common tables shared among different applications.
We need to access these tables (read-only, there would be no updates) but I don't want Doctrine to manage them. My vision is to create an entity for it so Doctrine can use it, including relations to it, but not have it do create/alter table statements when I do doctrine:schema:update.
Am I overthinking this?
Create your entities (manually or using generator) and mark them as readOnly

Symfony 2: Howto Map 2 way multiple Entities with one FormType

Suppose i have an Bundle to manage anything related to advertisements.
This bundle contains an Entity Advertisement. this has an field for relation purposes: lets say relation field
Suppose i have an Entity Company and an Entity Events in different Bundles
(In companies there are companies stored and in events there are events stored.)
Case:
The entities have a relation to multiple Advertisements.
A single Advertisement has a relation to only one of the entities.
From the perspective advertisement:
I want to be able to select one of the entities (entity.id) to view or update the reference (like dropdown)
From the perspective of an event or a company:
I want to be able to select/add/delete multiple advertisements (like the symfony collection form type)
all this preferred without the use of foreign-keys.
the entities are like "modules" so there can be more than just these entities.
I think you just have to use OneToOne (For Advertisement) and OneToMany (For Company and Events) relations.
It's easy to use, read this doc : http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html

Need Help on entity framework

I have 3 tables(Roles,Actions and RoleActionLinks). Roles table has few columns(RoleID,RoleName,Desc). Actions table has few colums(ActionID,ActionName,Desc). In RoleActionLink is created for store the association between Roles and Actions and this table has the columns such as RoleID,ActionID
When I created the data model(edmx). it shows only Role and Action as entity. i did not find RoleActionLink table. but even there is no direct relation between Roles and Actions table, both tables are automatically related using RoleActionLink table.
When i create the new Action, a action record should be populated in Action table(this is works fine). At the same time, i need to populate record in RoleActionLinks table. But i dont have the entity to populate.
Please tell me how to accomplish my needs.
This should work:
newAction.Roles.Add(role1);
newAction.Roles.Add(role2);
Look at navigation properties in your model. There should be EntityCollection called Roles (name may differ).
Entity framework automatically handles n-n tables and creates collections on both sides.

Resources