Should we use ManyToMany along with OneToMany in the same entity if we need junction table with custom columns? - typeorm

When we create an entity using typeOrm and have ManyToMany relation it's not quite clear to me whether I should or not remove ManyToMany decorator and additionally add another OneToMany decorator or just replace ManyToMany with OneToMany here typeOrm docs
I'm trying to add entity for a junction table and want to correctly set relations. Currently I'm using both decorators at the same time. Is that correct?

Related

How do I cascade a delete from the many side of a unidirectional one-to-many in GORM

If I have the following unidirectional one to many relationship between two domain classes:
class Single {
static hasMany = [ multiples: Multiple ]
}
class Multiple {
...
}
Is there a way to cascade the delete from the Multiple class to the many relationship on Single?
What I have found that works is to add to add an onDelete: Cascade property to the FK that exists on the multiple_id column of the join table via the database script - however what I would really like to do is to express this in the GORM mapping DSL (and without creating a separate domain class to explicitly represent the join table). But there does not appear to be a way to manage relationships on the implicit join table of a uni one-to-many - unless I've missed something.
Is there a reason not to use bidirectional? If not, take a look at http://grails.org/doc/2.4.x/ref/Domain%20Classes/belongsTo.html?

ADO.NET Entity Data Model handle parent-child relation in the same table

In my application I use ADO.NET Entity Data Model for data access.
I have the table categories (id, parentId, name, displayName). I want to access the children of a category. Does ADO.NET Entity Data Model support this behavior ... or I have to query manually each time? I would prefer to have the children in a List property that is lazy loaded.
Thanks,
Radu D
Yes it supports such relation. If you have the relation defined in your database this association should be created automatically when you update model from database. If you don't have this relation defined in database you can define it manually in the model as foreign key association. Here is some general example how to define a relation. You just need to do that on the same entity.

Own table for an Entity Framework 4 one-to-many association

I'm using the model-first approach offered by the EF4. I have two entities: User and Feature. As you would imagine, a User has a collection of Feature. After modeling this association and generating the SQL, the result is that the table Feature has a FK to User. What I want is to have the EF generate another table UserFeatures to store the relationships. Is there a way to do this without modeling the UserFeatures entity?
EF will create such table only if you want to model M:N relation. There is no reason to have such table for 1:N and EF don't generate it unless you somehow model it in designer.

EF 4.0 Self Referencing Many-To-Many relationship with Additional attribute

I'm using EF 4.0 and was able to create self referencing many to many relationship. Person and family members. What I also want is to add additional attribute like 'mother', 'brother', 'sister' for each relationship. At the database level, this model generates two tables. Person and PersonRelationship. PersonRelationship table has person_id, and relative_id as PK. I like to have another column relationshiptype in PersonRelationship table and reference in EF 4.0. Please let me know how to do it if you don't mind?
If I were you I would create a table "RelationshipTypes". It holds the different possible types of relationship for you. Just two columns ID and Name of relationship.
Second you just add the RelationshipTypeID to your PersonRelationship and mark it as primary key too.
You should have then three primary keys in your table. Just update your model in Visual Studio and it should work.
Does this help?
Regards Thomas

Hibernate many-to-many mapping

I am one of hibernate user in Australia. Recently, I have been dealing with hibernate many-to-many mapping and not going well though.
I got in trouble with "join/associate table with extra columns mapping".
Let`s say there are three tables called Product Order and OrderProduct (includes extra column quantity). Product holds many-to-many relationship with Order.
My confusion is that do we have to consider both ends of associate table when we are writing mapping files? or just write either side?
Also, is it necessary to produce mapping file for the associate table as well?
Any suggestions will be appreciated!!
create a view to join two tables. this view and rest table is many to one relationship
Hope it's userful
You should have an association mapping and entity because you need to create them just like an other entity.

Resources