# Problem with associations that could be null sometimes

**URL:** <https://www.ruby-forum.com/t/problem-with-associations-that-could-be-null-sometimes/156581>\
**Category:** Rails\
**Created:** [December 30, 2008, 10:53am UTC](https://www.ruby-forum.com/t/problem-with-associations-that-could-be-null-sometimes/156581 "2008-12-30T10:53:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cassiozen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cassiozen](https://www.ruby-forum.com/u/cassiozen)\
**Post date:** [December 30, 2008, 10:53am UTC](https://www.ruby-forum.com/t/problem-with-associations-that-could-be-null-sometimes/156581/1 "2008-12-30T10:53:00Z")

</div>

Hi Everybody,

I’m developing a little task management system with a Task model that  
belongs to Users and Projects.

The problem is that sometimes a task won’t belongs to an user AND a  
project. It will be possible to add a task to a project without  
delegate it to any user. In a similar way, it will be possible for  
users to create a new task without assigning it to any project.

So, my question is: Can I simply create the belongs\_to associations  
for the Task model and leave the foreign\_ids empty in the cases where  
the task doesn’t have an user or a project? Is there a better  
solution?

Thanks.

---

<div class="post-metadata">

**Author:** ![cassiozen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ed655f/32.png) [@cassiozen](https://www.ruby-forum.com/u/cassiozen)\
**Post date:** [December 31, 2008, 1:08am UTC](https://www.ruby-forum.com/t/problem-with-associations-that-could-be-null-sometimes/156581/2 "2008-12-31T01:08:40Z")

</div>

Yes, you can 🙂
