Allen Bierbaum | 15 May 17:21
Picon

Challenging relationship: many-to-many, custom join, mapped dictionary, can it work???


I am trying to setup a many-to-many relationship for two tables where
I would like to allow more natural access to the data using a
dictionary interface.  The exact usage is pretty complex to explain,
but I have come up with a simple example that demonstrates the same
concept. (there is a full code example at the end of the e-mail)

The tables are:
  - Script: holds a code script to run
  - VarTypes: Type details for variables that can be used as input and
output to the script

The relationship is:
  - For each Script, there is a set of named variables.
  - Each variable has a type associated with it
  - Each variable can be either an input variable or an output variable

What I want to allow in the end is something like this:

script = Script()
script.code = "test code"

var1 = VarType()
var2 = VarType()
var3 = VarType()
var4 = VarType()

script.input_vars["in1"] = var1
script.input_vars["in2"] = var2
script.output_vars["out1"] = var3
(Continue reading)

Michael Bayer | 15 May 18:37

Re: Challenging relationship: many-to-many, custom join, mapped dictionary, can it work???


On May 15, 2008, at 11:23 AM, Allen Bierbaum wrote:

> # ---- WOULD LIKE --------- #
> # Can this be done using
> # - Custom join condition on input_output_type
> # - column_mapped_collection
> #

it can be done.  Try working first with two separate relation()s using  
a secondary join that filters on "input" or "output" (theres an  
example of something similar in the docs); then add  
column_mapped_collection in.

Alternatively, use just one relation, and build dict-like proxies on  
top of it (i.e. class descriptors which return a custom object that  
has a __getitem__ method, which then reads back to the main relation  
to get data).  This the more manual route but is not terribly  
complex.  A not quite the same thing example of this can be seen at: 
http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/dynamic_dict/dynamic_dict.py 
  .

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

(Continue reading)

Allen Bierbaum | 15 May 21:54
Picon

Re: Challenging relationship: many-to-many, custom join, mapped dictionary, can it work???


On Thu, May 15, 2008 at 11:37 AM, Michael Bayer
<mike_mp <at> zzzcomputing.com> wrote:
> On May 15, 2008, at 11:23 AM, Allen Bierbaum wrote:
>> # ---- WOULD LIKE --------- #
>> # Can this be done using
>> # - Custom join condition on input_output_type
>> # - column_mapped_collection
>> #
>
> it can be done.  Try working first with two separate relation()s using
> a secondary join that filters on "input" or "output" (theres an
> example of something similar in the docs); then add
> column_mapped_collection in.

Will do.

The thing that I am missing though is an example of using
column_mapped_collection with a many-to-many relationship.  Maybe I am
just a bit slow, but I can't wrap my head around how to make that work
or more specifically, how to specify it.

Thanks,
Allen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
(Continue reading)

Michael Bayer | 15 May 22:18

Re: Challenging relationship: many-to-many, custom join, mapped dictionary, can it work???


On May 15, 2008, at 3:54 PM, Allen Bierbaum wrote:

> The thing that I am missing though is an example of using
> column_mapped_collection with a many-to-many relationship.  Maybe I am
> just a bit slow, but I can't wrap my head around how to make that work
> or more specifically, how to specify it.

it shouldnt be any different than using it with a one to many  
relationship.  Unless you have additional columns in your many-to-many  
table, in which case you wouldnt use M2M, youd use the association  
pattern.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---


Gmane