greetings,
i don't seem to be able to figure out how to map an input dictionary
to
my objects. specifically, i am trying to map a dictionary with inut
values to my session objects. somewhat stylized, using a non-
declarative approach:

book_table = Table('test_book', meta,
    Column(u'id', Integer, primary_key=True),
    Column(u'title', Unicode(255)),
    mysql_engine='InnoDB')

author_table = Table('test_author', meta,
    Column(u'id', Integer, primary_key=True),
    Column(u'first_name', Unicode(255)),
    Column(u'last_name', Unicode(255)),
   # Column(u'book_id', Integer, ForeignKey('test_book.id')),
    mysql_engine='InnoDB')

book_author_table = Table('test_book_author', meta,
    Column(u'user_id', None, ForeignKey('test_book.id'),
primary_key=True),
    Column(u'author_id', None, ForeignKey('test_author.id'),
primary_key=True))

meta.create_all()

class Author(object):pass
class Book(object): pass

mapper(Author, author_table)
mapper(Book, book_table)

in the simple case,  i got an input dict with only one author
(although there might be more than one):
in_dict = in2 = {'title':"some title 2", 'first_name':'joe',
'last_name':'somebody'}

my first flup is right here as i can't append the author to the author
list in the book oject, since it doesn't exist, duh:
book = Book()
author=Author()
book.authors.append(author) #does not work

how do i kneed to specify my metadata and mappers to get things set up
my way? is this even possible in a non-declarative manner?

although i haven't gotten there, yet, i'm pretty sure the _this_ won't
work even if i had my author obj list available:
for k,v in in_dict.items():
    book.k = v

fundamentally, i'm trying to get a web-based input form with lots of
attributes equivalent to the book-author example above into my db as
painless as possible. any suggestions are greatly appreciated, thx
matt




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to