Re: [Rails] Re: how to specify relationship between these models

2010-03-19 Thread Michael Pavling
On 19 March 2010 11:43, Tom Mac  wrote:
> why everything is stored in a single table

That's called Single Table Inheritance (STI)

> Can we store each items for say staff,director etc  to
> there own tables? Or Am I wrong?

You're not wrong; you can do it with different tables if you want.

Data modelling is done however is best for you. Sometimes you might
start with STI, refactor to associations, and then refactor back to
STI as your project requirements evolve.
Problems may occur when, for instance, your Managers also need to have
elements of the properties of Staff - you can't inherit from two
base-classes, so you have to start looking at mixing-in modules
instead, or of some other method of structuring your data to make it
make sense. Also, what happens if you have someone who's a staff
member of two offices (if that's possible for your organisation)? Can
they have different roles in the different places? etc...

Personally, I tend to keep "users" as a table for
authentication-related info, and in my "people" table (I'd tend to
avoid STI for people) I keep personal info, link to a user record, and
assign a "role" which is used for handling permissions. I'd rather
have lots of associations for data, because that's more flexible than
one wide flat table (the likes of which STI generally leads to...)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: how to specify relationship between these models

2010-03-19 Thread Tom Mac
Hi
 Thanks for your reply. This I have already thought of. But one 
thing I can't understand is why everything is stored in a single table 
say users here? Can we store each items for say staff,director etc  to 
there own tables? Or Am I wrong?

Tom
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: how to specify relationship between these models

2010-03-19 Thread Veera Sundaravel
Let say

you are having staff, directors and managers as part of your system, and 
their details will be in users table so let say we can build inheritance 
based relationship like below:

Class User  < ActiveRecord::Base
end

Class Staff < User
end

Class Director < User
end

Class Manager < User
end

users table:
id
type
name
email
phone
city
state etc

Now just you can create staff, directors as follows

staff = Staff.create(:name=>"Tom Mac", :email=>"tom@xyz.com")

So it will create one record in users table and mark the column type 
with "Staff". Hope it will solve your issue.

Regards.
T.Veeraa
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.