Questions tagged [self-referencing-table]

Refers to database tables with a column that is a foreign key to another column within the same table.

131 questions
0
votes
2 answers

Laravel Eloquent self relations

I'm new in Laravel and have problem with self relations in eloquent. I have table users with fields id and referrer, where referrer is foreign key to table users (each user have one referrer which is also users). And table invoice has relation to…
Bogdan Dubyk
  • 4,756
  • 7
  • 30
  • 67
0
votes
0 answers

Creating a treeview from a self referencing data table

I am working on a project that reads an XML file with information about metal bars and the cut lengths that are required on each bar. I want to display this data in a tree view, sorted by bar supplier then bar type, then individual bars. The…
Will
  • 17
  • 3
0
votes
2 answers

RoR: Model referencing itself multiple times

I have a Room model. Each room has 6 exits (north, east, south, west, up, down), and I should be able to do things like Room.first.nr to get the room to the north of the first one. The model I crafted is the following: class Room <…
0
votes
2 answers

Many-to-Many relationship with same table and with relationship constraint

I have a SellerProduct table. Each row within the table represents product information as offered by a seller. The SellerProduct table has the following columns: id (serial, pk) productName (nvarchar(50)) productDescription (ntext) productPrice…
James
  • 2,876
  • 18
  • 72
  • 116
0
votes
2 answers

Migration from Oracle to MariaDB - Trigger, Self-referencing table

I'm migrating my Oracle database to MariaDB, and I am unsure how to create a self-referencing ID on one of my tables. Essentially, if a belongs_to_id is not specified, it will assume that it belongs to itself (and be the same as the ID generated ON…
ash
  • 1,224
  • 3
  • 26
  • 46
0
votes
1 answer

EF cast to view model tree structure

I have a model in entity framework with parent child relationship in same table. It is a 0,1 to many mapping. Now it have many properties, at one scenario I don't want all these properties, just Id, Name and Children. public partial class Foo { …
Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54
0
votes
1 answer

Select [COLUMN_NAME] AS, self referencing table

The following is my function get_reportees performed on the self referencing table emp_tabref1 CREATE OR REPLACE FUNCTION get_reportees4(IN id integer) RETURNS TABLE(e_id integer, e_name character varying, e_manager integer, e_man_name character…
Adarsh Philip
  • 69
  • 1
  • 1
  • 7
0
votes
1 answer

Oracle: Recursively self referential join with nth level record

I have self referential table like this: id |level | parent_id ---------------------- 1 |1 |null 2 |1 |null 3 |2 |1 4 |2 |1 5 |2 |2 6 |3 |5 7 |3 |3 8 |4 |7 9 |4 …
Nik Kashi
  • 4,447
  • 3
  • 40
  • 63
0
votes
1 answer

OneToOne bidirectional self-referencing relationship, the first column not being created

I'm trying to create 1:1 bidirectionl self-referencing relationship like this: class User extends AbstractUser implements UserInterface { ..... /** * @var User */ private $binaryParent; /** * @var User */ …
xurshid29
  • 4,172
  • 1
  • 20
  • 25
0
votes
0 answers

Different behaviour of self referential model. Is it a bug?

It seems that I found a bug. I have two similar models that behave differently. I have a Post model that belongs_to an Author. I have a Task model that is self-referencing. Model code: app/models/author.rb: class Author < ActiveRecord::Base …
woto
  • 2,893
  • 1
  • 29
  • 24
0
votes
1 answer

How to diff and intersect Many-To-Many Self-referencing ArrayCollections

I have Many-To-Many Self-referencing relation in my user entity. // Acme\DemoBundle\Resources\config\doctrine\User.orm.yml Acme\DemoBundle\Entity\User: type: entity repositoryClass: Acme\DemoBundle\Entity\Repository\UserRepository table:…
0
votes
0 answers

Can I insert multiple rows for self-referencing table at same time when inserted rows reference each other?

I've got a self-referencing table that has a nullable, unique FK column referencing the PK for another row in the same table. This forms a linked list structure. I've got all of my various interactions working, including insertions -- just go…
Dan
  • 3,246
  • 1
  • 32
  • 52
0
votes
1 answer

What is the most efficient way of storing complex, self-referencing tree structures in an SQL database?

I'm aware of and have used two methods in the past for basic tree structures: adjacency lists and nested sets. I understand several pros and cons to these approaches - e.g., that adjacency lists are quick to update but slow to query, that nested…
magnus
  • 4,031
  • 7
  • 26
  • 48
0
votes
4 answers

Mysql get latest row of self referencing relationship

I have a comments table and allow people to edit their comments. Instead of overwriting comments I create a new comment and associate it to its "parent". Additionally, I add the child information to the parent. id, user_id, comment_id__parent,…
n00b
  • 16,088
  • 21
  • 56
  • 72
0
votes
1 answer

EF Code First 6 With "Multiple" many to many self referencing

I have one entity like this: public class Course { public int Id { get; set; } public string Name { get; set; } public virtual ICollection Prerequisites { get; set; } public virtual ICollection Equivalents { get;…
ILIA hu
  • 147
  • 1
  • 1
  • 5
1 2 3
8
9