I believe you would specify the column names you would like the new column to 
be which forms the relationship:
infinitives = elixir.ManyToMany( 'WordFormsMapping',colname='infinitive_id'...
That should get the 'infinitive_id' column name into infinitives.
I think that including the "local_side = 'wordform_id'" in the relationship 
definition is probably what's causing the 
"wordforms_wordform_id1" and "wordforms_wordform_id2". Also maybe a bit of a 
stranglehold on the relationship definition--Elixir will do the job, just let 
it. 



-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
Behalf Of Roinet
Sent: Tuesday, June 17, 2008 7:54 AM
To: SQLElixir
Subject: [elixir] Custom foreign keys names in ManyToMany relationship.



I need a way to define custom names for foreign keys. I have a DB with
the following scheme:

CREATE TABLE wordforms (
        wordform_id INTEGER NOT NULL,
        word TEXT NOT NULL,
        infinitives_loaded BOOLEAN NOT NULL,
        PRIMARY KEY (wordform_id)
)

CREATE TABLE infinitives (
        wordform_id INTEGER NOT NULL,
        infinitive_id INTEGER NOT NULL,
        PRIMARY KEY (wordform_id, infinitive_id),
         CONSTRAINT wordforms_infinitives_fk FOREIGN KEY(wordform_id)
REFERENCES wordforms (wordform_id) ON DELETE CASCADE ON UPDATE
CASCADE,
         CONSTRAINT wordforms_infinitives_inverse_fk FOREIGN
KEY(infinitive_id) REFERENCES wordforms (wordform_id)
)

I have defined entity class for wordforms mapping :

class WordFormsMapping( elixir.Entity ) :
    elixir.options.using_options( tablename = 'wordforms', session =
None, autosetup = True )

    wordform_id = elixir.Field( elixir.Integer, primary_key = True )
    word = elixir.Field( elixir.Text, index = True, nullable = False )
    infinitives_loaded = elixir.Field( elixir.Boolean, index = True,
nullable = False, default = False )
    infinitives = elixir.ManyToMany( 'WordFormsMapping',
                                      tablename = 'infinitives',
                                      remote_side = 'wordform_id',
                                      local_side = 'wordform_id',
                                      uselist = True,
                                      backref = 'forms',
                                      onupdate = 'CASCADE',
                                      ondelete = 'CASCADE' )

which generates the following SQL:

CREATE TABLE wordforms (
        wordform_id INTEGER NOT NULL,
        word TEXT NOT NULL,
        infinitives_loaded BOOLEAN NOT NULL,
        PRIMARY KEY (wordform_id)
)

CREATE TABLE infinitives (
        wordforms_wordform_id1 INTEGER NOT NULL,
        wordforms_wordform_id2 INTEGER NOT NULL,
        PRIMARY KEY (wordforms_wordform_id1, wordforms_wordform_id2),
         CONSTRAINT wordforms_infinitives_fk FOREIGN
KEY(wordforms_wordform_id1) REFERENCES wordforms (wordform_id) ON
DELETE CASCADE ON UPDATE CASCADE,
         CONSTRAINT wordforms_infinitives_inverse_fk FOREIGN
KEY(wordforms_wordform_id2) REFERENCES wordforms (wordform_id)
)

where names wordforms_wordform_id1 and wordforms_wordform_id2 are used
instead of wordform_id and infinitive_id which I have in DB.
How can I customize these columns naming?



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to