flask - SQLALchemy filter_by() on a foreign key producting weird sql -


i'm attempting filter on foreign key , none of answers i've searched have lent results.

where query statements.

testing = comments\     .filter(comments.post_id==post_id) print(testing)  testing = comments\         .query.join(post, aliased=true)\         .filter(comments.post_id==post_id) print(testing) 

here's class definitions looks like

class comments(db.model):      comment_id =  db.column(db.integer, primary_key=true)     post_id = db.column(         db.integer,         db.foreignkey("post.post_id"),         nullable=false)  class post(db.model):     post_id =  db.column(db.integer, primary_key=true)  comments = db.relationship(         'comments',         backref='post',         lazy='dynamic') 

the actual sql queries being produced first , second case. both have weird :post_id_1 thing. in both cases i'm getting null set back.

from "comments"  "comments".post_id = :post_id_1  "comments" join "post" "post_1" on "post_1".post_id = "comments".post_id  "comments".post_id = :post_id_1 

if simple

select * comments post_id = 1

in mysql cli result set.

your model definition weird, following part not correctly indented:

comments = db.relationship(         'comments',         backref='post',         lazy='dynamic') 

or maybe it's copy/paste issue (just sure).

what call "weird :esc_id_1 thing" in fact named placeholder. replaced real value when sql statement executed (this avoid sql injection, driver responsible escape values).


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -