entity-relationship

doctrine2: how to convert a one-to-many to a many-to-many without losing data

让人想犯罪 __ 提交于 2019-12-06 02:01:14
问题 In my application, I want to convert a one-to-many to a many-to-many without losing the data : from: /** * @ORM\ManyToOne(targetEntity="\AppBundle\Entity\FoodAnalytics\Recipe", inversedBy="medias") * @ORM\JoinColumn(name="recipeId", referencedColumnName="id", onDelete="CASCADE") */ protected $recipe; to: /** * @ORM\ManyToMany(targetEntity="\AppBundle\Entity\FoodAnalytics\Recipe", inversedBy="medias") * @ORM\JoinTable( * name="media_recipes", * joinColumns={@ORM\JoinColumn(name="mediaId",

Hibernate one to many relationship with join table with addition columns in join table

混江龙づ霸主 提交于 2019-12-06 01:56:51
I am looking for a way to have a @OneToMany relation between two tables and having extra attributes in the join table and I am not able to find much useful examples around. Sorry if this sounds lame but can any suggest me a good way for it. If you have additional columns in the join table, it's not a join table anymore, and you need a way to get and set values in these columns. So the answer is simple: the table needs to be mapped as an entity. For example, let's say you have a Person entity and an Address entity. And the person has several addresses. Now let's say each address must be

Doctrine: Object of class User could not be converted to string

吃可爱长大的小学妹 提交于 2019-12-06 01:23:54
问题 I keep getting this error with Doctrine: PHP Catchable fatal error: Object of class User could not be converted to string in vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1337 In my system users can have many permissions in a One to Many relationship. I have set up a User and Permission entity. They look like this (I removed some annotations, getters and setters to reduce clutter): class User { /** * @ORM\Column(name="user_id", type="integer", nullable=false) * @ORM\Id * @ORM

How to set up Primary Keys in a Relation?

二次信任 提交于 2019-12-06 00:03:39
I wish to know how to correctly set up Primary Keys in a Relation . E.g. we have ER-diagram which contain elements: Key attributes Weak key attributes Identifying relationships Associative entities In order to translate it into Relational Model we should do some tricks. All elements above deal with Primary Keys of relations but they all are Natural Keys - so we can leave them as is or replace with Surrogate Keys . Consider some cases. Case 1 Key Attribute is a name - so it must be of type CHAR or VARCHAR . Generally names become Key Attributes . Case 2 Two (or more) Identifying Relationships

Database design for custom form builder (and storage of results)

南楼画角 提交于 2019-12-05 22:16:26
问题 I'm trying to implement a custom form builder, similar to those provided by Wufoo and Google. While I've created a simple UI to create these custom forms with, my issues lie in the database design. Upon creating the form, a JSON implementation is saved in the database (would like to improve this) and referenced to build the form that a user would see. Upon submission, I'd like to store all of the fields of the form in a database. Following the JSON structure used for designing the database,

How can I associate one record with another in the same table?

核能气质少年 提交于 2019-12-05 20:51:49
I have created a cable database in Access, and I generate a report that has lists the connectors on each end of a cable. Each cable has its own ID, and 2 connector IDs, associated with it. All the connectors are from the same table and is linked to many other tables. I need 2 fields in one table (cable) associated with 2 records in the second table. My solution was to create 2 more tables: A primary connector table and secondary connector table, each of which has all entries from the first connector table. Then I could create columns in the cable ID Table for the primary and secondary IDs. The

Is there data visualisation tool for postgresql which is capable of displaying inter schema relations as well? [closed]

时光怂恿深爱的人放手 提交于 2019-12-05 11:58:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Operating system used is linux. I have tried Navicat and SQL Power Architect . They did display relations between tables in the same schema. I have some foreign key constraints which reference tables in a different schema. Am I missing something with respect to Navicat and PostgreSQL Maestro? Can they not

Can I set an entity relation with just the ID?

南笙酒味 提交于 2019-12-05 07:01:25
I have a JPA (Hibernate) entity: @Entity class Transaction { @ManyToOne private Room room; } When I create a new Transaction , I know the ID of the Room that it should refer to (but don't have a Room object). Can I somehow create and persist a Transaction with just this info, or do I really need to: Room room = em.find(roomId, Room.class); em.persist(new Transaction(room, ...)); You can use EntityManager.getReference() to get a proxy of the related entity without accessing the database. This proxy is lazy-initialized and will be initialized only when you query anything other than the ID if the

EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)

混江龙づ霸主 提交于 2019-12-05 03:38:14
I have the following class: public class User { public Guid Id { get; set; } public string Name { get; set; } public Couple Couple { get; set; } } public class Couple { public Guid Id { get; set; } public User Groom { get; set; } public User Bride { get; set; } } Important points: Bride and Groom properties are required One-to-one relationship In the User class, it is Couple required DbContext in OnModelCreating modelBuilder.Entity<User>().HasRequired(u => u.Couple).WithRequiredPrincipal(); modelBuilder.Entity<Couple>().HasRequired(u => u.Bride).WithRequiredDependent(); modelBuilder.Entity

Should I use an index column in a many to many “link” table?

主宰稳场 提交于 2019-12-05 00:37:10
问题 I have two tables, products and categories which have a many to many relationship, so I'm adding a products_categories table which will contain category_id and product_id . Should I add another (auto-incrementing) index column or use the two existing ones as primary key? 回答1: That depends. Are you seeing your data more as set of objects (and relational database is just a storage medium) or as set of facts represented and analyzed natively by relational algebra. Some ORMs/Frameworks/Tools don