Hi all, 

So I'm trying to do something fairly standard, I'm creating a db mapped 
object which has a many-to-one relationship to another db mapped class. I'm 
basically "inheriting" and bunch of attribute values from that relationship 
and so I want to populate those fields by reading from the relationship and 
populate them with the appropriate values found in that relationship. The 
issue is is that the relationship always seems to be returning None, which 
is strange seeing as when I do a straight session.query for that object it 
is definitely able to get it. 

Here is the code I'm talking about:

def create(record):
        parent = record.acquisition_request *# <----- Parent is always None 
here!*
        record.product_type = parent.product_type
        record.line_item = parent.line_item

        session = get_scoped_session()

        session.add(record)
        try:
            session.commit()
        except:
            session.rollback()
            raise

And here is the relationship constructor that I am trying to access:

acquisition_request = relationship("AcquisitionActive",
                                  
 primaryjoin='AcquisitionActive.acquisition_request_id == 
AcquisitionOpportunityActive.acquisition_request_id',
                                   backref="acquisition_opportunities",
                                   foreign_keys=acquisition_request_id, 
uselist=False)

Wondering if it's something that can't be resolved before a db flush or 
something? Doesn't seem right as I am not querying on any surrogate key or 
anything, just some a foreign key (which is present in the object).

Hope this is enough information, thanks for any help you guys have.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to