Doing no more than comparing your image with your code:
- 1..many means that the many must refer to the one
- 1..1 you decide which end you want the reference on
- many..many you need a table to hold reference pairs; select all
refernce "a" of an id to find the many "b"s it refers to; select all
refernce "b"s of an id to find the many "a"s it refers to.
Having said this, I will just make _some_ sample comments below
First, I assume your diagram is correct for what you want (which may not be
so).
Reading your image top-left to right, then down,
I see many users refer to a happening, so I look for users reference to
happening (per comments above);
The many-to-many requires some reference table such as
db.define_table('users_tag', SQLField('users_id', 'reference users'),
SQLField('tag_id', 'reference tag'))
Next (moving right) I see 1-happening..many-event, so I expect a reference
from event.
I think from here you can probably sort out the rest, from the pattern I
have shown.
Regards,
Yarko
On Sun, Mar 15, 2009 at 11:41 AM, Jason Brower <[email protected]> wrote:
> Not really experienced in database design so I figure I can throw this
> up to the crowd to get some feedback.
>
> Let me tell you my confusions now:
> I don't get how to properly do multiplicity. I think I am doing it
> right with:
> SQLField('foo',db.bar)
> But I have no clue how that actually makes multiplicity. And by what
> feilds is it basing that on? How do I read that data? What owner has
> has how many dogs?
> And isn't:
> db.foo.bar.requires = [IS_IN_DB(db,'ding.bat')]
> A multiplicity?
> Hope I am clear enough.
>
> I have entered the following into my model.
> -------------------------------------------------
>
> db = SQLDB("sqlite://ALittleDB.db")
>
>
> db.define_table("tag",
> SQLField("name", "string"),
> SQLField("description", "text"),
> SQLField("logo", "upload"),
> SQLField("created", "date"),
> SQLField("creator", "string"))
>
>
> db.define_table("event",
> SQLField("topic", "string"),
> SQLField("description", "text"),
> SQLField("date", "date"),
> SQLField("start_time", "time"),
> SQLField("end_time", "time"),
> SQLField("maximum_participants", "integer"),
> SQLField("minimum_participants", "integer"),
> SQLField("logo", "upload"),
> SQLField("created", "datetime"),
> SQLField("creator","string"),
> SQLField("language","string"),
# missing reference:
SQLField('id_happening', 'reference happening'),
>
> SQLField("type","string"))
>
>
> db.define_table("language",
> SQLField("name", "string"),
> SQLField("language_code", "string"))
>
>
> db.define_table("location",
> SQLField("name", "string"),
> SQLField("description", "text"),
> SQLField("address", "string"),
> SQLField("capacity", "integer"),
> SQLField("inventory", "text"),
> SQLField("created", "datetime"),
> SQLField("logo", "upload"),
> SQLField("id_event", db.event))
>
>
> db.define_table("users",
> SQLField("first_name", "string", length=15),
> SQLField("last_name", "string", length=15),
> SQLField("nickname", "string", length=15),
> SQLField("phone_number", "string", length=15),
> SQLField("email", "string"),
> SQLField("company", "string", length=25),
> SQLField("position", "string"),
> SQLField("street", "string"),
> SQLField("city", "string", length=30),
> SQLField("postal_code", "string", length=15),
> SQLField("country", "string", length=30),
> SQLField("created", "date"),
> SQLField("avatar", "upload"),
SQLField('id_happening', 'reference happening'), #... how you write
a forward reference
>
> SQLField("id_tag", db.tag))
>
>
> db.define_table("happening",
> SQLField("name", "string", length=50),
> SQLField("description", "text"),
> SQLField("website", "string", length=50),
> SQLField("street", "string", length=25),
> SQLField("city", "string"),
> SQLField("postal_code", "string"),
> SQLField("country", "string"),
> SQLField("maximum_capacity", "integer"),
> SQLField("beginning_date", "date"),
> SQLField("ending_date", "date"),
> SQLField("logo", "upload"),
> SQLField("created", "datetime"),
> SQLField("id_users", db.users), # wrong - this would implement
> many-happening to one-user
# this should
be in users table... not here...
>
> SQLField("id_location", db.location),
> SQLField("id_event", db.event)) # wrong - as above...
>
> db.define_table("event_type",
> SQLField("name", "string"),
> SQLField("description", "text"),
> SQLField("id_event", db.event),
> SQLField("logo", 'upload'))
>
> db.users.first_name.requires = [IS_NOT_EMPTY()]
> db.users.last_name.requires = [IS_NOT_EMPTY()]
> db.users.nickname.requires = [IS_NOT_IN_DB(db,'users.nickname')]
> db.users.email.requires = [IS_EMAIL(),IS_NOT_IN_DB(db,'users.email')]
> db.users.position.requires =
> [IS_IN_SET(['administrator','guest','visitor','staff'])]
> db.users.created.requires = [IS_NOT_EMPTY()]
> db.users.avatar.requires = [IS_NOT_EMPTY()]
>
> db.tag.name.requires = [IS_NOT_EMPTY()]
> db.tag.description.requires = [IS_NOT_EMPTY()]
> db.tag.creator.requires = [IS_IN_DB(db,'users.nickname')]
> db.tag.logo.requires = [IS_NOT_EMPTY()]
> db.tag.created.requires = [IS_NOT_EMPTY()]
>
> db.event_type.name.requires = [IS_NOT_EMPTY()]
> db.event_type.description.requires = [IS_NOT_EMPTY()]
> db.event_type.logo.requires = [IS_NOT_EMPTY()]
>
> db.event.topic.requires = [IS_NOT_EMPTY()]
> db.event.description.requires = [IS_NOT_EMPTY()]
> db.event.date.requires = [IS_NOT_EMPTY()]
> db.event.start_time.requires = [IS_NOT_EMPTY()]
> db.event.end_time.requires = [IS_NOT_EMPTY()]
> db.event.maximum_participants.requires = [IS_NOT_EMPTY()]
> db.event.minimum_participants.requires = [IS_NOT_EMPTY()]
> db.event.type.requires = [IS_IN_DB(db,'event_type.name')]
> db.event.logo.requires = [IS_NOT_EMPTY()]
> db.event.created.requires = [IS_NOT_EMPTY()]
> db.event.creator.requires = [IS_IN_DB(db,'users.nickname')]
> db.event.language.requires = [IS_IN_DB(db,'language.name')]
>
> db.happening.name.requires = [IS_NOT_EMPTY()]
> db.happening.description.requires = [IS_NOT_EMPTY()]
> db.happening.beginning_date.requires = [IS_NOT_EMPTY()]
> db.happening.ending_date.requires = [IS_NOT_EMPTY()]
> db.happening.logo.requires = [IS_NOT_EMPTY()]
> db.happening.created.requires = [IS_NOT_EMPTY()]
>
> db.language.name.requires = [IS_NOT_EMPTY()]
> db.language.language_code.requires = [IS_NOT_EMPTY()]
>
> db.location.name.requires = [IS_NOT_EMPTY()]
> db.location.description.requires = [IS_NOT_EMPTY()]
> db.location.address.requires = [IS_NOT_EMPTY()]
> db.location.created.requires = [IS_NOT_EMPTY()]
> ------------------------------------------------------
>
> I am trying to draw this out with DIA. I have used the JS versions and
> they have helped me a lot in learning how they are constructed. But I
> am faster typing it in the end.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---