then you have to look up an existing Category and use that.

theres a recipe to make this automatic:

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject


On Mar 10, 2007, at 9:29 AM, sqad wrote:

>
> I have 2 tables.
>
> One that maps categories (schema: Category) that are created/
> initialized when database is first created:
> ---------------------------------------------------------------------- 
> ---------------------------------------
> -category_id (primary-key),
> -category_name
>
> [sample STATIC-CONSTANT table mappings]
> 1 , 'Local'
> 2 , 'Global'
> etc.,
>
> Another that contains (schema: Event):
> ---------------------------------------------------------------------- 
> ---------------------------------------
> -event_id (primary-key),
> -category_id (foreign-key),
> -date,
> -etc,
>
> This is a one to one relationship. I am using Pylons MVC framework
> with SA. When creating an Event object which requires association with
> a category, how do I map it?
>
> I have the following mappers:
>
> assign_mapper(session_context, Category, category_table)
> assign_mapper(session_context,
>        Event,
>        event_table,
>        properties = {'category' : relation(Category, cascade="all,
> delete-orphan")}
>
> Basically, what's the syntax to create the event with some category?
> This doesn't work.
> event.category = Category("Local")
>
> It creates a NEW entry in the "Category" table, which is not what I
> wanted. I want to basically link the Event table to the Static
> Category table through reference of the primary/foreign-key
> relationship.
>
> Thanks!
>
> /sqad
>
>
> >


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

Reply via email to