Hi All,
I am having a very bad day (or two to be honest), spending time
reading error messages.
I am sorry to say but the SQLALCHEMY documentation is not very helpful
when using declarative_base.... when it is about relations......
It should be very easy for you database guy's (which I'm not, I'm more
of a protocoll/low level programmer)
The problem.
I am implementing a calendaring system based on the ical specification.
Consider the following ( I'll keep it as simple as possible):
I am using MySQL 5.+
SQLAlchemy 0.5.6
Class | __tablename__
----------------+----------------------
Calendar | Calendars
Event | CalendarEvents
Todo | CalendarTodos
Alarm | CalendarAlarms
XProp | CalendarXProps
(Tablenames do not reflect Objectnames, sorry for that, it is a
requirement)
so:
class XProp(Base):
__tablename__ = "CalendarXProps"
Id = Column(Integer, primary_key=True)
EventId = the Id of the event this XProp belongs to
AlarmId = the Id of the Alarm this Xprop belongs to
CalendarId = The Id of the Calendar ..........
Name = Column(.......
Value = Column(......
(either EventId or AlarmId or CalendarId is used)
class Event(Base):
__tablename__ ="CalendarEvents"
Id = Column(Integer, primary_key=True)
CalendarId = the ID of the Calendar this Object belongs to
XProps = relation zero or more XProp (I would like to
do: for
XProp in self.XProps: ...... )
X = Column(....
Y = Column(...
def __init__(self):
self.Xprops = [ ]
self.X = "X"
self.Y = 576234
class Alarm(Base):
__tablename__ ="CalendarAlarms"
Id = Column(Integer, primary_key=True)
CalendarId = the ID of the Calendar this Object belongs to
XProps = relation zero or more XProp
X = Column(....
Y = Column(...
def __init__(self):
self.Xprops = [ ]
self.X = "X klsdjkladsjkd ddsa"
self.Y = 5
class Calendar(Base):
__tablename__ = "Calendars"
Id = Column(Integer, primairy_key=True)
Events = relation One Calendar zero or more Events
(i.e. [ ],
[Event,Events,Event,....]
Alarms = relation One Calendar zero or more Alarms
XProps = relation, One Calendar zero or more XProp
X = Column(....
Y = Column(...
def __init__(self):
self.Events = [ ]
self.Alarms = [ ]
self.Xprops = [ ]
self.X = "X"
self.Y = 576234
cal = Calendar()
the X, Y, Name and Value columns indicate example record data)
The Errormessages are allways on the line with cal = Calendar(),
saying the original errormessage has probaby been lost due to
hasattr.....
Not very helpfull since over 40 objecttypes are trying to do the same
thing.
Whatever I do with ForeignKey, backref, relation keeps popping up
errors whenever I try to make a Calendar Instance (e.g. cal = Calendar
() )
One or mappers failed to compile.....
The big problem is that the tablenames are not equal to the Object
names and that seems to confuse SQLAlchemy .
Many errors (every time I run my program It generates a different error)
Like" table 'Calendar' " not found (I never said there is a table
Calendar, that is the objectname, I specify Calendars.Id)
Can someone please help me with the setting up the relations. in the
example above to give me a starting point. (there are about 40 XProp
alike Objects and some Alarm/Even alike objects, I have reduced the
above example to the minimum possible)
So what I need is help with the relation and Foreign Key columns
including the backrefs (I need to search CalendarEvents and find the
corresponding Calendar)
Thank you very mutch!!!!
Martijn
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---