On Nov 29, 2007, at 8:10 AM, PaStIcHiO wrote:

>
> Hi to everyone:
> i have a question for you, since i haven't found the solution in the
> docs.
> Is there such a way to store in a extra column an information that
> belongs to some property of an object?
> I'll try to be clear with an example:
>
> I have an object Person, and many linked object Addresses. So this is
> a relation one to many.
> An object Addres has a property "Street". One of these addres  is the
> main  one for that person.
> I would like to have this information stored in a column of the
> person.
>
> Basically i found something in the docs  that more or less is near
> what i want:
>
> def mydefault():
>    global i
>    i += 1
>    return i
>
> t = Table("mytable", meta,
>    # function-based default
>    Column('id', Integer, primary_key=True, default=mydefault),lt")
> )
>
> But i would like that the function that i can call belongs to the
> object that i want to save,
> not to generic static function.
> I hope that i was clear in explaining my problem.
>
> All the best,
> Andrea
>

there is a particular way we store the usual "person contains  
addresses, but one address is his or her favorite", which is to have a  
foreign key "favorite_address_id" on the person table.  this means  
that there are foreign keys in both directions.  if you wanted to go  
with that, theres an option called "post_update" on relation() which  
makes it possible.

in this case, the "default" function is a strange choice since your  
program is going to need to specifically pick the "favorite" address  
and set it explicitly.  using a default function doesnt change that,  
it just makes it more complicated to communicate, since your program  
would have to put the "favorite" data somewhere where the "default"  
picks it up.  why not just explicitly set the data in the "person"  
insert ?




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

Reply via email to