# Foreign key on the same table testing

**URL:** <https://www.ruby-forum.com/t/foreign-key-on-the-same-table-testing/120050>\
**Category:** Rails\
**Created:** [November 13, 2007, 11:51am UTC](https://www.ruby-forum.com/t/foreign-key-on-the-same-table-testing/120050 "2007-11-13T11:51:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascalschudel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@pascalschudel](https://www.ruby-forum.com/u/pascalschudel)\
**Post date:** [November 13, 2007, 11:51am UTC](https://www.ruby-forum.com/t/foreign-key-on-the-same-table-testing/120050/1 "2007-11-13T11:51:21Z")

</div>

Hi @all

I wrote a rails app and now I want to test it.  
For this, I’d like to use test fixtures wich I created in .yml-files.  
In my model, each object can include another object. This  
is done by a foreign key. Unfortunately, there is always an error  
becaus of a  
foreign key constraint which fails. Does anybody knows how to solve this  
problem?  
My .yml-file looks like this:  
one:  
id: 1  
person\_id: 1  
father: null  
person\_type: parent  
two:  
id: 2  
person\_id: 2  
father: 1  
person\_type: child

If I only insert the first one, it works…

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![pascalschudel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@pascalschudel](https://www.ruby-forum.com/u/pascalschudel)\
**Post date:** [November 13, 2007, 1:56pm UTC](https://www.ruby-forum.com/t/foreign-key-on-the-same-table-testing/120050/2 "2007-11-13T13:56:38Z")

</div>

On Nov 13, 2:51 am, Pa Sc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> one:  
> If I only insert the first one, it works…
> 
> ## Thanks for your help!
> 
> Posted viahttp://www.ruby-forum.com/.

it isn’t clear if your’e doing single table inheritance (STI) or a  
acts\_as\_nested\_set (or acts\_as\_tree) structure, but these are both  
well-established techniques with constraints on column names, if you  
do a search for them
