# Sub accounts

**URL:** <https://www.ruby-forum.com/t/sub-accounts/185515>\
**Category:** Rails\
**Created:** [March 22, 2010, 3:38am UTC](https://www.ruby-forum.com/t/sub-accounts/185515 "2010-03-22T03:38:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 3:38am UTC](https://www.ruby-forum.com/t/sub-accounts/185515/1 "2010-03-22T03:38:23Z")

</div>

I am using restful authentication and was wondering if anyone has had  
any experience with sub accounts. Basically, I want a user to have the  
ability to add another user(s) to his/her account. So if user A  
creates an account I would like them to have the ability to add new  
users to their account - B, C, etc. B and C would “belong” to A and if  
A’s account is deleted so is B and C. Makes sense? Any information on  
how to achieve this would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 6:33am UTC](https://www.ruby-forum.com/t/sub-accounts/185515/2 "2010-03-22T06:33:22Z")

</div>

mlittle wrote:

> I am using restful authentication and was wondering if anyone has had  
> any experience with sub accounts. Basically, I want a user to have the  
> ability to add another user(s) to his/her account. So if user A  
> creates an account I would like them to have the ability to add new  
> users to their account - B, C, etc. B and C would “belong” to A and if  
> A’s account is deleted so is B and C. Makes sense? Any information on  
> how to achieve this would be greatly appreciated.

This can be done by using the relationships among the tables.  
I suggest the following database model:

## Users ( Table )

ID  
Name

sub\_users ( Table)

ID references Users(ID)  
UserID

In the models

Users =\> has\_many :sub\_users  
sub\_users =\> belongs\_to :User

so, you should delete first sub\_users records, then Users table records.

---

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 6:38am UTC](https://www.ruby-forum.com/t/sub-accounts/185515/3 "2010-03-22T06:38:05Z")

</div>

On Mar 21, 10:33 pm, Loganathan G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I suggest the following database model:  
> UserID
> 
> In the models
> 
> Users =\> has\_many :sub\_users  
> sub\_users =\> belongs\_to :User
> 
> ## so, you should delete first sub\_users records, then Users table records.
> 
> Posted viahttp://www.ruby-forum.com/.

Seems too easy :). How would I handle the confirmation email and  
related issues? Thanks a bunch for the response. I do appreciate it!!

---

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 6:46am UTC](https://www.ruby-forum.com/t/sub-accounts/185515/4 "2010-03-22T06:46:03Z")

</div>

mlittle wrote:

> On Mar 21, 10:33ï¿½pm, Loganathan G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I suggest the following database model:  
> > UserID
> > 
> > In the models
> > 
> > Users ï¿½ =\> has\_many :sub\_users  
> > sub\_users =\> belongs\_to :User
> > 
> > ## so, you should delete first sub\_users records, then Users table records.
> > 
> > Posted viahttp://www.ruby-forum.com/.
> 
> Seems too easy :). How would I handle the confirmation email and  
> related issues? Thanks a bunch for the response. I do appreciate it!!

I don’t really understand what are you trying to mean about confirmation  
email and related issues ?  
If u don’t mind can u explain me in detail?

Thanks

---

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 6:16pm UTC](https://www.ruby-forum.com/t/sub-accounts/185515/5 "2010-03-22T18:16:25Z")

</div>

Anyone else able to provide me with some insight on implementing this?

---

<div class="post-metadata">

**Author:** ![mlittle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mlittle](https://www.ruby-forum.com/u/mlittle)\
**Post date:** [March 22, 2010, 6:57am UTC](https://www.ruby-forum.com/t/sub-accounts/185515/6 "2010-03-22T06:57:24Z")

</div>

On Mar 21, 10:46 pm, Loganathan G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > so, you should delete first sub\_users records, then Users table records.  
> > > Thanks  
> > > –  
> > > Posted viahttp://www.ruby-forum.com/.

I’m going to look at the code more but I was talking about creating  
the user just like I would with restful\_authentication. I see what you  
are saying but I am still not clear how the new user in sub\_user would  
be able to login, logout, and basically do the same as the users in  
Users.
