Hi, i'm starting a new project with pyramid and sqlalchemy. I have a slight problem with testing the project when using attribute_mapped_collection in a relationship
class Movie(Base):
__tablename__ = 'movies'
id = Column(Integer, primary_key=True)
uid = Column(String(30), nullable=False, unique=True)
fsk = Column(Integer)
length = Column(Integer)
language_id = Column(Integer,
ForeignKey(Language.id, ondelete="cascade"),
nullable=False)
language = relation(Language)
year = Column(Integer)
titles = relation('MovieTitle',
collection_class=attribute_mapped_collection('language_id'),
cascade="all, delete-orphan")
class MovieTitle(Base):
__tablename__ = 'movie_titles'
id = Column(Integer, primary_key=True)
movie_id = Column(Integer,
ForeignKey(Movie.id, ondelete="cascade"),
nullable=False)
movie = relation(Movie)
language_id = Column(Integer,
ForeignKey(Language.id, ondelete="cascade"),
nullable=False)
language = relation(Language)
title = Column(String(80), nullable=False)
headline = Column(String(80))
subtitle = Column(String(80))
for unittesting i create in setUp some entries for the movies and
movietitles tables.
for mi in testdata_movies:
mtis = mi.pop('titles', [])
movie = Movie(**mi)
self.session.add(movie)
self.session.flush()
for mti in mtis:
mt = MovieTitle(movie_id=movie.id, **mti)
self.session.add(mt)
self.session.flush()
testdata_movies = [
{
'id': 1,
'country_id': 1,
'language_id': 1,
'year': 2011,
'fsk': 12,
'length': 123,
'titles': [
{
'language_id': 1,
'title': 'Testfilm',
'subtitle': "testsubtitle",
}
]
}
]
Running this code generates the entry in movies table but no entry in
movietitles. what am i doing wrong.
Regards
Estartu
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/807c0e4b-ee7f-00a2-33fa-71222467e158%40augusta.de.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
