# Factory Girl Associations Issue with Uniqueness Validations

**URL:** <https://www.ruby-forum.com/t/factory-girl-associations-issue-with-uniqueness-validations/162888>\
**Category:** Rails\
**Created:** [March 15, 2009, 4:41am UTC](https://www.ruby-forum.com/t/factory-girl-associations-issue-with-uniqueness-validations/162888 "2009-03-15T04:41:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![redii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@redii](https://www.ruby-forum.com/u/redii)\
**Post date:** [March 15, 2009, 4:41am UTC](https://www.ruby-forum.com/t/factory-girl-associations-issue-with-uniqueness-validations/162888/1 "2009-03-15T04:41:09Z")

</div>

Greetings,

Does anybody have a workaround/solution for Factory Girl’s insistence on  
creating a new record for each association it creates? As far as I can  
tell, this makes using Factory Girl unusable when you have uniqueness  
validations on the model referenced by the FK when testing interrelated  
has\_many/belongs\_to associations.

What am I missing here? Google shows many people with same issue  
without a clear resolution. I may just need some sleep. 🙂

Thanks

TMA

---

<div class="post-metadata">

**Author:** ![redii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@redii](https://www.ruby-forum.com/u/redii)\
**Post date:** [March 19, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/factory-girl-associations-issue-with-uniqueness-validations/162888/2 "2009-03-19T21:30:07Z")

</div>

I have exactly the same problem… but no solution. Would also greatly  
appreciate suggestions as to a workaround.

---

<div class="post-metadata">

**Author:** ![redii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@redii](https://www.ruby-forum.com/u/redii)\
**Post date:** [March 20, 2009, 8:25am UTC](https://www.ruby-forum.com/t/factory-girl-associations-issue-with-uniqueness-validations/162888/3 "2009-03-20T08:25:04Z")

</div>

On Thu, Mar 19, 2009 at 8:01 PM, mirts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have exactly the same problem… but no solution. Would also greatly  
> appreciate suggestions as to a workaround.
> 
> >

When I encounter this type of issue, I tend to create the high level  
objects and then explicitly include them

@author = Factory(:author)

book1 = Factory(:book, :author =\> @author)  
book2 = Factory(:book, :author =\> @author)  
etc.

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain
