Hi!

I've got an answer on Stack ( http://stackoverflow.com/questions/35653889/sqlalchemy-property-mapping/35654405 ) - solution uses relationship and an association proxy. But I also found out that it can be achieved via hybrid property. How to do this?

I have following models:

|class  Details(db.Model):

    details_id=  db.Column(db.Integer,  primary_key=True)
    details_main=  db.Column(db.String(50))
    details_desc=  db.Column(db.String(50))

class  Data(db.Model):

    data_id=  db.Column(db.Integer,  primary_key=True)
    data_date=  db.Column(db.Date)
    details_main=  db.Column(db.String(50))

    @property
    def  details_desc(self):

        result=  object_session(self).\
            scalar(
                select([Details.details_desc]).
                    where(Details.details_main==  self.details_main)
            )

        return  result|


Now, I would like to run query using filter which depends on defined property. I get an empty results (of course proper data is in DB). It doesn't work because, probably, I have to map this property. The question is how to do this? (One limitation: FK are not allowed in this DB's design).

|Data.query\
    .filter(Data.details_desc==  unicode('test'))\
    .all()|



Cheers,
TomS

Exported from Notepad++

--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to