Issue: join select error
Author: rfyiamcool
State: closed
Created: 2016-10-11 10:45:58

### this sql syntax is error ?   the two table not has fk relation .

```
ProductAndCategory.select(ProductAndCategory.top_name, ProductAndCategory.second_name, ProductAndCategory.third_name, Product.pname, Product.pid).join(Product, on=((Product.pid == ProductAndCategory.pid) & (Product.product_ident != '')))
```

error:

```
Traceback (most recent call last):
  File "scripts/write_json.py", line 62, in <module>
    write_json()
  File "scripts/write_json.py", line 58, in write_json
    product_cat_save()
  File "scripts/write_json.py", line 40, in product_cat_save
    for p in res:
  File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1462, in next
    obj = self.iterate()
  File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1448, in iterate
    self.initialize(self.cursor.description)
  File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1565, in initialize
    fk_name = join.on._alias or join.on.lhs.name
AttributeError: 'Expression' object has no attribute 'name'
```

detail error

```
In [2]: res = ProductAndCategory.select(ProductAndCategory.top_name, ProductAndCategory.second_name, ProductAndCategory.third_name, Product.pname, Product.pid).join(Product, on=((Product.pid == ProductAndCategory.pid) & (Product.product_ident != '')))

In [3]: res.first()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-51088aa74006> in <module>()
----> 1 res.first()

/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in first(self)
   2003     def first(self):
   2004         res = self.execute()
-> 2005         res.fill_cache(1)
   2006         try:
   2007             return res._result_cache[0]

/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in fill_cache(self, n)
   1474         while not self._populated and (n > self.__ct):
   1475             try:
-> 1476                 self.next()
   1477             except StopIteration:
   1478                 break

/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in next(self)
   1460             return inst
   1461
-> 1462         obj = self.iterate()
   1463         self._result_cache.append(obj)
   1464         self.__ct += 1

/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in iterate(self)
   1446             raise StopIteration
   1447         elif not self._initialized:
-> 1448             self.initialize(self.cursor.description)
   1449             self._initialized = True
   1450         return self.process_row(row)

/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in initialize(self, description)
   1563                     if not fk_field:
   1564                         if isinstance(join.on, Expression):
-> 1565                             fk_name = join.on._alias or join.on.lhs.name
   1566                         else:
   1567                             # Patch the joined model using the name of the

AttributeError: 'Expression' object has no attribute 'name'
```

Thanks U  !!!


i know , thanks !