class Brand(BaseModel): name = CharField()
class Meta: table_name = 't_brand'
class Bin(BaseModel): id = AutoField(column_name='ID') bank_name = CharField() bin = CharField() brand = ForeignKeyField(column_name='brand_id', model=Brand) cobrand_id = IntegerField(null=True) product = CharField(null=True)
class Meta: table_name = 't_bin'
from models import Bin, Brand
query = Bin.select(Bin.bin, Bin.bank_name, Brand.name.alias('brand')).join(Brand)
('SELECT "t1"."bin", "t1"."bank_name", "t2"."name" AS "brand" FROM "t_bin" AS "t1" INNER JOIN "t_brand" AS "t2" ON ("t1"."brand_id" = "t2"."id")', [])626247 Aloqabank None626248 Qishloq qurilish ban None626249 Ipak Yo`li Bank None
Could you help to figure out the problem?
rom peewee import *
database = SqliteDatabase('binbase.db')
class UnknownField(object): def __init__(self, *_, **__): pass
class BaseModel(Model): class Meta: database = database
class SqliteSequence(BaseModel): name = BareField(null=True) seq = BareField(null=True)
class Meta: table_name = 'sqlite_sequence' primary_key = False
query = Bin.select(Bin.bin, Bin.bank_name, Brand.name)).join(Brand)
query = Bin.select(Bin.bin, Bin.bank_name, Brand.name.alias('brand'))).join(Brand)
--
You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/1329498b-45ce-40cd-bae9-e26374319912%40googlegroups.com.
class Bin(BaseModel): id = AutoField(column_name='ID') bank_name = CharField() bin = CharField() brand = ForeignKeyField(column_name='brand_id', model=Brand)
cobrand = IntegerField(column_name='cobrand_id',null=True) country = ForeignKeyField(column_name='country_iso2_code', field='alpha_2_code', model=Country)
product = CharField(null=True)
class Meta: table_name = 't_bin'
query = (Bin .select(Bin.bin, Bin.bank_name, Brand.name, Cobrand.name, Country.name ) .join(Brand) .switch(Bin) .join(Cobrand, JOIN.LEFT_OUTER, on=cobrand_predicate) .switch(Bin) .join(Country))
626247 Aloqabank UNION PAY Uzbekistan
626296,Kapital bank,UZCARD,UNION PAY,Uzbekistan860002,NBU,UZCARD,null,Uzbekistan
Peewee resolves your models into a graph, so:
query = Bin.select(Bin.bin, Bin.bank_name, Brand.name)).join(Brand)
for q in query:print(q.bin, q.bank_name, q.brand.name)You can use the ".objects()" method to disable this:
query = Bin.select(Bin.bin, Bin.bank_name, Brand.name.alias('brand'))).join(Brand)
for q in query.objects():print(q.bin, q.bank_name, q.brand)
To unsubscribe from this group and stop receiving emails from it, send an email to peewe...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/72a43b1c-9a60-4727-be71-9228401f0d57%40googlegroups.com.
In your join() call you'll want to specify an attr to patch the Cobrand stuff onto:# For example:.join(Cobrand, JOIN.LEFT_OUTER, on=cobrand_predicate, attr='cobrand')Then the Cobrand data will be available on the "cobrand" attr.
To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/72a43b1c-9a60-4727-be71-9228401f0d57%40googlegroups.com.