On Wed, Jul 1, 2009 at 2:18 AM, Adrien Coquio<[email protected]> wrote:
>
> Thanks but it's not a good solution for my problem : one user can have
> several mandates for several various locations !
> For example :
> table ELECTED
> (2,Adrien Y,king,Brasil)
> (4,Adrien Y,mayor,Rio)
>
> In the first case, the location is a Country and in the second the
> location is a City then i think i can't do that with your solution,
> i'm wrong ?
> adrien

So the way I understand this is that the mandates table is really
providing the valid combinations of place type and position, so that
you can be the king of a state, or the mayor of a city, but not the
mayor of a state, or the king of a city.

If I were doing this, I'd just have the mandate table (possibly with a
different name) hold the valid combinations, and use it to populate a
select lists for office_name and place_time attributes in an object
representing that a user holds a particular office in a particular
place.  I'd probably name this  Office instead of Elected since some
offices like Mayor are held by election, while others such as king are
not.

And I'd probably have a validation method in Office which ensured that
there really was a mandate with the given office_name and place_type.


Table: USERS
- id
- name
has_many :offices

Table: CITY
- id
- name
:has_many :offices, :as => :place

Table: STATES
- id
- name
:has_many :offices, :as => place

Table: MANDATES
- id
- name
- place_type = city or states

Table: OFFICES
- id
- user_id
- office_name
- place_id
- place_type #copied from the mandate when the office is created.
:belongs_to :user
:belongs_to :place, :polymorphic => true


-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to