Hi,

I want to make a relation such that.. i have users post some
articles.. and can link them as relatd to other articles.

I have the Article table like this:
articles = Table('articles', metadata,
    Column('id', Integer, primary_key=True),
    Column('topic', Unicode(256), nullable=False),
    Column('rank', Integer),
    Column('content', Unicode, nullable=False),
    mysql_engine='InnoDB'
)

And I have a related articles association table like this:

articles_related_articles =
   Column('article_id', Integer, ForeignKey('articles.id'),
index=True, nullable=False),
    Column('related_id', Integer, nullable=False),
    Column('bias', SmallInteger, default=0),
    mysql_engine='InnoDB'
)


So, if article 1 is related to article 2.. then there should be two
rows in the articles_related_articles table like:
> 1 2 0
> 2 1 0

This is how I make the relation mapping in SA:

mapper(ArticleRelatedArticle, articles_realted_articles,
       primary_key=[articles_realted_articles.c.article_id,
articles_related_articles.c.related_id],
       properties={'article': relation(Article),}
)

assign_mapper(context, Article, articles,
     'related': relation(ArticlesRelatedArticles, cascade="all, delete-
orphan", lazy=True)
)


I am doing this in the shell, but its not working as expected. I dont
see those two rows created, and related_id is always getting
overrideen to NULL, even though I have it specified while creating the
object.

In [1]: a = Article.select()[0]
In [3]: a.id
Out[3]: 1L
In [4]: b = Article.select()[1]
In [5]: c = ArticlesRelatedArticles(article_id=a.id, related_id=b.id)
In [6]: a.related.append(c)
In [7]: session.flush()
/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.4-py2.4.egg/sqlalchemy/
databases/mysql.py:313: Warning: Field 'related_id' doesn't have a
default value

Now, checking the db, this is what I have:
mysql> select * from articles_related_articles;
+-------------+------------+------+
| articles_id | related_id | bias |
+-------------+------------+------+
|           1 |          0 |    0 |



can someone help me with what could be wrong with my code?

thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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