Results 1 to 6 of 6
  1. #1
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default help with mapping and relationship

    Hi. thanks for taking the time. Im new to this. so please bare with me.

    This project is all about Users and Events.

    all users can create (become owner) of many Events.
    all users can join many Events
    the owner can accept or deny Joined Users.

    my database looks like this now.

    users : id, name, emal, password.
    events : id, body, ownerId.
    joined_events : id, ownerId, userId, eventId, is_accepted, is_denied.

    I have not specified any relationship as it is now, so I use jsql to set/get the columns in joined_events.

    Its time to upgrade and to my question:
    Is this called that I have a one-to-many, one-to-one or many-to-many relationship between Users and Event ?

  2. #2
    hotplugin is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default

    It should be one-to-many.

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Users to Events is many-to-many for membership. The way you have your Events table laid out, it's one-to-many for ownership, but you may want to re-think that -- it may be useful to allow Events to have more than one Owner.

    I would do something like this:

    Users: id, name, email, password_hash (don't store plain-text passwords)
    Events: id, body
    Membership: event_id, user_id, accepted (Yes, No, Pending)
    Ownership: event_id, user_id

    -Gary-

  4. #4
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by gcalvin View Post

    I would do something like this:

    Users: id, name, email, password_hash (don't store plain-text passwords)
    Events: id, body
    Membership: event_id, user_id, accepted (Yes, No, Pending)
    Ownership: event_id, user_id

    -Gary-
    Thank you both for taking the time.

    In Garys example, would that make the following realationships ?

    many-to-many between Users and Events. = create new table "Ownership" ?
    one-to-many between Membership and Ownership. ?

    Hm I cant see what good the Table Membership does. Cant I just move the column "accepted" into "Ownership" ?

    Many questions =)

    / Peace

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Users get accepted or denied for Membership, not for Ownership, right? There is no direct relationship between Membership and Ownership. Both Membership and Ownership define relationships between Users and Events, and both of those (in my design) are many-to-many. If each group is to have only one owner, then you don't need the Ownership table. Instead, you have an Owner field on the Events table, as you originally designed. I think it's useful to allow multiple Owners (if this is a real-world project). It can be dangerous to have all administrative power in one user's hands. What if that user dies, or quits, or just forgets his password?

    -Gary-

  6. #6
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default

    If you could see me now, you would see a big light bulb over my head. What you say make sense . I will do a make over on my design. Thankś

    / peace

Similar Threads

  1. class relationship
    By RajShri in forum New To Java
    Replies: 2
    Last Post: 01-04-2010, 05:54 AM
  2. How to update data for a JPA many-to-many relationship?
    By abhijit.sarkar in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 11-04-2008, 08:48 AM
  3. Relationship Manager (HR, Marketing) - Mindlance
    By mindlance777 in forum Reviews / Advertising
    Replies: 1
    Last Post: 10-31-2008, 04:38 AM
  4. What is this Object relationship?
    By SirRawlins in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 03:17 PM
  5. problem with ejb 3.0 entity beans with manyToMany relationship
    By makcro in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-26-2007, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •