Forum: Ruby on Rails Problem with associations that could be null sometimes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3264e5664540abc9002b3a1f6f6f9f21?d=identicon&s=25 cassiozen (Guest)
on 2008-12-30 10:53
(Received via mailing list)
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.
8c52a1a66395899cfee24caeb4f57e97?d=identicon&s=25 Ivor Paul (apie)
on 2008-12-31 01:08
(Received via mailing list)
Yes, you can :)
This topic is locked and can not be replied to.