Refers to database tables with a column that is a foreign key to another column within the same table.
Questions tagged [self-referencing-table]
131 questions
13
votes
1 answer
Map category parent id self referencing table structure to EF Core entity
Database Table:
I tried this approach to map the category table to EF core:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity(entity =>
{
entity
.HasMany(e => e.Children)
…

lschmid
- 183
- 1
- 1
- 11
10
votes
1 answer
How to create Hibernate Mapping for a self referencing table
I was asked how I would create a hibernate mapping for a column in a table that refers to the primary key of the table.
For example, an Employee table has EMP_ID as primary key and it also has MGR_ID column to know the manager of the employee. As a…

chandra
- 129
- 1
- 1
- 8
8
votes
3 answers
EF6 Self Referencing Table with multiple parent properties, single child collection
I have a table that references itself, but I am struggling with getting my desired mapping. I want to be able to define Children to be a collection of people that have a given person as Mother, Father, and/or Guardian. A Guardian may be the father…

Mothware
- 312
- 2
- 10
7
votes
1 answer
ON DELETE SET NULL on self referencing relationship
I have the table with one primary key and one foreign key referencing the same table primary key.
i.e there are parents and childs in the same table. In sql sever there are three options for the delete rule. But it is only possible to set "NO…

mattti
- 121
- 4
7
votes
1 answer
How to change the ordering of sql execution in hibernate
I am trying to model bidirectional parent-child design, with ordered children.
When removing child (eg. child #2 of 3 children) from the parent, hibernate's generated sql led to unique constraint violation because "update" (sibling) is being…

YeenFei
- 3,180
- 18
- 26
6
votes
1 answer
How to efficiently load data from a self related table
Consider the following requirement for building a forum App
Parent Post
- Child Post1
- Child Post1-1
- Child Post1-2
- Child Post1-2-1
- Child Post2
- Child Post
- Child Post3
Table Structure
tblPost
-…

Perpetualcoder
- 13,501
- 9
- 64
- 99
5
votes
1 answer
Reverse self referencing foreign key in Django
Sorry if this is a stupid question, but I'm a bit of a Django newbie and can't find the answer.
I have an Order model with a self-referencing field:
source = models.ForeignKey(
'self',
help_text = "[redacted]",
verbose_name = "Source…

charredUtensil
- 153
- 1
- 11
4
votes
2 answers
Self Referencing Table SQL query
I've table with four columns id, name, designation, manager_id.
Table schema:
CREATE TABLE "Employee_Information"
(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" varchar,
"designation" varchar,
"manager_id" integer…

Aravind
- 534
- 1
- 6
- 18
4
votes
2 answers
Modeling Employee-Assistant(s) relationship with EF Code First
Here are the business requirements, in short:
All employees need to be stored in a database
Some employees have assistants, some do not
Some employees have more than one assistant
Assistants are employees, as well
There is obviously a bit of a…

Jiveman
- 1,022
- 1
- 13
- 30
4
votes
3 answers
How to define a filter box out of the ng-table?
All
I create a filter box in ng-table following the instrunctions of http://bazalt-cms.com/ng-table/example/4
my code is same as the example:
create filter in html: