Thanks for the accurate answer, it have a lot of sense to have an add method
but I didn't know that it existed.

2008/5/17 Oleg Broytmann <[EMAIL PROTECTED]>:

> On Sat, May 17, 2008 at 01:59:03AM +0200, Luis Javier Peris wrote:
> > 'm working with SQLObject and I'm getting frustated because of lack of
> > examples. First of all, I'm having problems creating tables with
> > many-many relationships
> > by means of RelatedJoin. I want to create and know how work the CRUD
> > operations in the tables created by RelatedJoin operation. I have two
> tables
> > I've created as follow:
> >
> > class Term(SQLObject):
> >     name = StringCol(default=None)
> >     description = StringCol(default=None)
> >     vocabulary = ForeignKey('Vocabulary')
> >     term_questions = RelatedJoin('Question', joinColumn='question',
> > otherColumn='term',
> >                                  intermediateTable='Term_questions')
> > Term.createTable(ifNotExists=True)
> >
> > class Question(SQLObject):
> >     question_file = StringCol(default=None, length=255, unique=True)
> >     question_name = StringCol(default=None)
> >     question_type = StringCol(default=None)
> >     term_questions = RelatedJoin('Term', joinColumn='term',
> > otherColumn='question',
> >                                  intermediateTable='Term_questions')
> > Question.createTable(ifNotExists=True)
> >
> > So, I have a new table with two columns (term and question). How CRUD
> > operations work?
> >
> > I've tried to create a new instance of Term_questions table:
> > Term_questions(term=term.id, question=q.id), but the module
> Term_questions
> > doesn't exist
>
>    It doesn't exist. If you want to explicitly declare it:
>
> http://sqlobject.org/FAQ.html#how-can-i-define-my-own-intermediate-table-in-my-many-to-many-relationship
>
> > or if I try:
> > q = Question(question_file="file", question_name= "name",
> > question_type="MultipleChoice")
> > term.term_questions = q.id
> > I get: AttributeError: can't set attribute
>
>    term.term_questions is a list. If want to add an object to the join, use
> add*() methods:
>
> term.addQuestion(q)
>
>   or
>
> q.addTerm(term)
>
> Oleg.
> --
>     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
>           Programmers don't die, they just GOSUB without RETURN.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to