[sqlalchemy] Re: odd question

2008-01-30 Thread Gaetan de Menten

On Jan 23, 2008 10:24 PM, Monty Taylor [EMAIL PROTECTED] wrote:

 This may or may not be elixir specific...

 If I have an auto-generated mapping table for a many-to-many
 relationship, is there a sensible way to add another column to it that's
 also has a foreign key relationship to a third table?

 Like, if I had this:

 Products
   id int
   name varchar

 ProductTypes
   id int
   name varchar

 Groups
   id int
   name varchar

 and then I defined a many to many between products and groups to get

 products_groups
   product_id
   group_id

 and I wanted to add producttype_id to that ...

You'll probably want to use the Association Object pattern, as described at:

http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_patterns_association

And possibly, the AssociationProxy plugin, at:

http://www.sqlalchemy.org/docs/04/plugins.html#plugins_associationproxy

This one can be used with Elixir just fine. You just need to import it
from SQLAlchemy:

from sqlalchemy.ext.associationproxy import AssociationProxy

-- 
Gaƫtan de Menten
http://openhex.org

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



[sqlalchemy] Re: odd question

2008-01-23 Thread Michael Bayer


On Jan 23, 2008, at 4:24 PM, Monty Taylor wrote:


 This may or may not be elixir specific...

 If I have an auto-generated mapping table for a many-to-many
 relationship, is there a sensible way to add another column to it  
 that's
 also has a foreign key relationship to a third table?

 Like, if I had this:

 Products
  id int
  name varchar

 ProductTypes
  id int
  name varchar

 Groups
  id int
  name varchar

 and then I defined a many to many between products and groups to get

 products_groups
  product_id
  group_id

 and I wanted to add producttype_id to that ...


If you're asking about creating mappers, a many-to-many table has  
exactly two foreign keys defined, that of a parent table and a child  
table.  Any columns which are not part of those two foreign keys  
disqualifies the table to be considered a many-to-many table by  
SQLAlchemy's ORM; youd have to map a class to the table explicitly.

if youre just talking about adding a column to a Table, i think theres  
an append_column() method which does that(check the docstrings)



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