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

On Jul 1, 1:01 am, AGoofin <[email protected]> wrote:
> First, try not to worry so much about how the tables are set up, you
> can create a view to the data to suit your needs. What you need to be
> concerned about is how to make the information easy to use and to not
> repeat yourself.
>
> As to modeling the data - It seems that the User table would be the
> central piece and he or she would have one mandate or perhaps more?
> Either has_one or has_many.
>
> It would also seem the user has a location as well as mandate. Another
> one to one relationship here and again, the user may have more then
> one location - has_one or has_many
>
> Model User
> id
> name
> etc.
> Has_one: mandate
> has_one: location
>
> Model Mandate
> id
> user_id
> etc.
> belongs_to :user
>
> Model Location
> id
> user_id
> etc.
> belongs_to :user
>
> Then you could have a look up table for the types of mandates and
> locations.
>
> Hope this helps
>
> On Jun 28, 12:48 pm, Adrien Coquio <[email protected]> wrote:
>
> > this solution doesn't fit with my project
>
> > i have to explain :
>
> > the table MANDATES contain the list of possible mandates like :
> > (0,mayor,city)
> > (1,deputy mayor,city)
> > (2,minister,state)
> > (3,king,state)
> > this list use by me to make a form where the user of my program can
> > select the mandate related by user
>
> > the table ELECTED contain the relation between user and mandate like :
> > (0,John Smith,mayor,Chicago)
> > (1,Brad X,mayor,New York)
> > (2,Adrien Y,king,Brasil)
> > (3,Anton Z,minister,Great Britain)
> > NB: i replace user_id,mandate_id,place_id by user.name,
> > mandate.name,place.name
>
> > the solution which i see to do that are :
> > 1)i have explain in the first post
> > 2) duplicate the field place_type in the table ELECTED (maybe it is
> > the easier solution?)
> > 3) group tables MANDATES and ELECTED like that :
> > MANDATES
> > - id
> > - name
> > - place_id
> > - place_type
> > - user_id
> > in that way i create all possible mandates with no user related to
> > make the form and when i have a relation between user/mandate i create
> > a copy of the mandate with the user_id
>
> > what do you think about this solution?
>
> > thanks
>
> > adrien
>
> > On Jun 28, 5:12 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
>
> > s.net> wrote:
> > > Adrien Nom wrote:
> > > > I want to do that way because i must save the possible mandates in one
> > > > table.
>
> > > That's not a good rationale.  The place_id is part of the mandate just
> > > as much as the olace_type is, so it belongs in the mandates table.
>
> > > > Then i use an other table to save the relation between mandates
> > > > and users.
> > > > How can i do that with an other way ?
>
> > > If I understand you correctly, this will be very easy with your current
> > > schema, once you make the change I am proposing.
>
> > > Basically, place_id is a property of the mandate, so it belongs in the
> > > mandates table.  Since you have mandate_id in elected, you can get the
> > > place_id with something like @elected.mandate.place_id.
>
> > > > thanks for your answer
> > > > adrien
>
> > > Best,
> > > --
> > > Marnen Laibow-Koserhttp://www.marnen.org
> > > [email protected]
> > > --
> > > Posted viahttp://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 [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