# Modelling data to specify user access

**URL:** <https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199>\
**Category:** Rails\
**Created:** [May 11, 2006, 2:30am UTC](https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199 "2006-05-11T02:30:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 11, 2006, 2:30am UTC](https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199/1 "2006-05-11T02:30:04Z")

</div>

Hello, this is my second Rails app, and the first one I did had simple  
data mapping. This time I am building a site for a photographer, and  
they want to upload photos, and create galleries that only certain  
clients can log in and have access to. There will be multiple  
galleries, and the access to them will vary depending on how the admin  
assigns it to each client. There is also a porftolio that everyone  
coming to the site can see. So I was thinking to have one master Images  
table that holds all the images, and divide it out into portfolio and  
galleries.

I am sitting down mapping the data right now, but I am not sure how to  
handle this. How many tables to I need and how do I map them together?  
So far I have these tables:

Users  
\*ID  
\*username  
\*password

Images  
\*ID  
\*image\_name  
\*path\_to\_image  
\*path\_to\_thumbnail

Galleries  
\*ID  
\*gallery\_name

and then I’m not sure about:

Gallery\_Names?  
User\_Access?

I’d appreciate help if anyone has had experience with this before…

Jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 11, 2006, 2:39am UTC](https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199/2 "2006-05-11T02:39:16Z")

</div>

The most basic way I see it is

gallery  
has\_many :pictures  
has\_many :users

So you just create the gallery and add a gallery\_id to the pictures  
table and to the users table.

Josh

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 11, 2006, 2:51am UTC](https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199/3 "2006-05-11T02:51:05Z")

</div>

Josh C. wrote:

> The most basic way I see it is
> 
> gallery  
> has\_many :pictures  
> has\_many :users
> 
> So you just create the gallery and add a gallery\_id to the pictures  
> table and to the users table.
> 
> Josh

Thanks, that part makes sense. I think though it might be more  
complicated? Each user can have access to more than one gallery, and  
each image can be in multiple galleries. Like if the client wants to  
present the same image in a different gallery taylored for each client.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 11, 2006, 3:00am UTC](https://www.ruby-forum.com/t/modelling-data-to-specify-user-access/60199/4 "2006-05-11T03:00:29Z")

</div>

On 5/10/06, Jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks, that part makes sense. I think though it might be more  
> complicated? Each user can have access to more than one gallery, and  
> each image can be in multiple galleries. Like if the client wants to  
> present the same image in a different gallery taylored for each client.

Then just change the has\_many to has\_and\_belongs\_to\_many then create a  
gallaries\_users and gallaries\_pictures table.

Josh
