Take a look at SQLAlchemy's ORM tutorial, it has a section dedicated to
implementing various relations (with declarative form included). Solution
for your task would be as you already mentioned - pretty easy:
1) Reference your table with a foreign key field, eg:
# 'remotetbl' is the table you are referring to
remotetbl_id = Column(Integer, ForeighKey('remotetbl.id'))
2) Define a relationship between your model classes, eg:
# Note: you may want to access objects the other way round (one-to-many) ,
take a look at 'backref' parameter for this.
remotetbl = relation('remotetbl')
This will do a many-to-one from your table -> 'remotetbl'.
Again, everything can be found in http://www.sqlalchemy.org/docs/.
Regards,
Patrick
On Tue, Oct 12, 2010 at 3:10 PM, Karen McNeil <[email protected]>wrote:
> I've tried going through the SQLObject tutorial. The problem is that
> it's not TG-specific, so some of the stuff it tells you to do (like
> setting up the mapping), are things that TG does for you so I
> shouldn't use that part of the code. But I'm not sure which parts are
> relevant and which parts are not.
>
>
> On Oct 12, 2:51 am, "Diez B. Roggisch" <[email protected]> wrote:
> > On Oct 12, 2010, at 4:10 AM, Karen McNeil wrote:
> >
> >
> >
> > > Turbogears is driving me crazy! I don't remember ever having this
> > > much trouble learning something new. My problem is that I learn by
> > > example, and TG is really failing me. Either the example for what I
> > > want to do doesn't exist, or it's wrong. All I want to do is create
> > > three related tables. The tutorials that show you how to do this are
> > > for TG 1, meaning they use SQLObject and a different syntax. The Wiki
> > > 2.0 tutorial doesn't have any related tables; the RestControllers
> > > tutorial does, but it's adding another layer of complexity that I
> > > don't understand and probably don't need.
> >
> > > My three tables are Corpus, Genres, and UploadedFiles. Each item in
> > > the corpus with be one of several genres (one-to-many), and will be
> > > associated with one or more files. (The files will only be associated
> > > with one corpus item, so that's also a one-to-many relationship, but
> > > going the other way.) This seems like it should be very easy to do,
> > > but I haven't been able to find straight-forward instructions on how
> > > to do it. I've wasted days and days, and I really hope you guys can
> > > help me... (I'm very new to TurboGears and pretty new to Python,
> > > also, so speak slowly and use small words...)
> >
> > > This is what I've got so far, and I know I'm missing some vital
> > > pieces:
> >
> > I don't know much about declarative from SQLAlchemy - we use Elixir.
> >
> > However, one tip: TG (one and two) are both composed of components that
> exist on their own. Such as Pylons, ToscaWigets and - for you the most
> interesting part - SQLAlchemy.
> >
> > And while it sometimes sucks, it's always a good idea to check out these
> pieces individual documentation, and possible mailinglists
> >
> > And in the case of SQLAlchemy, that is excellent. Both are.
> >
> > So I suggest you take a look at the SA documentation, and for any
> questions go to their ML.
> >
> > That is not to say that your question doesn't belong here. It might well
> be somebody here that is capable and willing to answer it. But chances are
> higher otherwise.
> >
> > Diez
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<turbogears%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en.