
Teno
30.11.2017
10:34:16
Thank you very much Alexander for your time

Alexander
30.11.2017
10:34:24
Sure

Teno
30.11.2017
10:34:34
additional columns?

Alexander
30.11.2017
10:35:24
When you define new Required or Optional attribute, it requires a new column. When you generated tables at first time, that column was missed

Google

Teno
30.11.2017
10:36:56
I'm working with an real database in MySQL. The columns exist in the database.

Matthew
30.11.2017
10:37:41
Double check the table and column names in the database

Alexander
30.11.2017
10:37:55
In the error message it says: Unknown column 'faclin2.facl_facc_descripcion' in 'field list'
So this column is not present in the database

Teno
30.11.2017
10:38:51
no, the column is facl_facc_descripcion in table Faclin
I don't know why the error says facl_facc_descripcion

Alexander
30.11.2017
10:39:30
Because you probably have a typo in entity definition

Matthew
30.11.2017
10:39:43
or upper case vs lower case table name maybe

Teno
30.11.2017
10:40:54
I removed that column and now I get: pony.orm.dbapiprovider.OperationalError: (1054, "Unknown column 'faclin2.faccab2_facc_id' in 'field list'")

Matthew
30.11.2017
10:41:38
I believe pony expects to only see columns that it knows about

Teno
30.11.2017
10:41:54
I think is connected with having two keys
for the primary, what do you think about?
Thank you for your time too Matthew

Google

Matthew
30.11.2017
10:42:44
No problem, waiting around for a flight, this is better than the work on my todo list ;)
run this in mysql and show us the output
DESCRIBE faclin2;

Teno
30.11.2017
10:43:04
ok

Alexander
30.11.2017
10:44:04
Actually, Pony is fine with column which is unknown to Pony, as far as that columns are optional.
At the start Pony makes a select for each table in order to be sure that all columns described in entity are really exists
It seems that some attributes are descibed in Entity, but does not have corresponding column in the table


Teno
30.11.2017
10:44:40
MariaDB [clp_pruebas2]> describe faclin2;
+------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| facl_facc_serie | varchar(10) | NO | PRI | NULL | |
| facl_facc_id | int(11) | NO | PRI | NULL | |
| facl_alb_id | bigint(20) | NO | PRI | 0 | |
| facl_numlinea | int(11) | NO | PRI | 0 | |
| facl_fecha | date | YES | | NULL | |
| facl_codarticulo | varchar(13) | YES | | NULL | |
| facl_descripcion | varchar(54) | YES | | NULL | |
| facl_cantidad | float(9,3) | YES | | NULL | |
| facl_preciocoste | decimal(11,4) | YES | | NULL | |
| facl_precio | decimal(11,4) | YES | | NULL | |
| facl_dto | float(4,2) | YES | | 0.00 | |
| facl_importe | float(10,3) | YES | | 0.000 | |
| facl_iva | tinyint(4) | NO | | 21 | |
| facl_talla | char(2) | YES | | NULL | |
| facl_color | char(2) | YES | | NULL | |
| createdAt | timestamp | YES | | NULL | |
| updatedAt | timestamp | YES | | NULL | |
+------------------+---------------+------+-----+---------+-------+
+------------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------------+------+-----+---------+-------+
| facc_serie | varchar(10) | NO | PRI | NULL | |
| facc_id | int(11) | NO | PRI | NULL | |
| facc_cli_id | int(11) | NO | MUL | NULL | |
| facc_fecha | date | YES | | NULL | |
| facc_hora | time | YES | | NULL | |
| facc_vencimiento | date | YES | | NULL | |
| facc_fechacobro | date | YES | | NULL | |
| facc_retencion | float(3,2) | YES | | 0.00 | |
| facc_for_id | tinyint(4) | NO | MUL | 0 | |
| facc_iva_id | tinyint(4) | NO | MUL | 0 | |
| facc_notas | text | YES | | NULL | |
| facc_dto | float(9,3) unsigned | YES | | 0.000 | |
| facc_re | float(9,3) | YES | | 0.000 | |
| createdAt | timestamp | YES | | NULL | |
| updatedAt | timestamp | YES | | NULL | |
+------------------+---------------------+------+-----+---------+-------+
faccab2
It's a normal master-detail relation between tables with a multiple primary key
Alexander, it's incredible for my I'm chatting with the main developer of Pony ? It's similiar to talk to a famous person for me. Thank you for your time and for your incredible software


Alexander
30.11.2017
10:51:48
Regarding composite keys:
If some entity has a composite primary key, then each Required or Optional attribute that rerers to these entity actually implemented using several columns. For example:
class Course(db.Entity):
name = Required(int)
semester = Required(str)
PrimaryKey(name, semester)
exams = Set('Exam')
class Exam(db.Entity):
dt = Reqired(date)
course = Required(Course)
In that example, Exam.course attribute actually adds two columns to Exam table: course_name and course_semester, because they both are needed for making a relationship. If you need to name these columns differently, you can specify correct names in attribute definition:
class Exam(db.Entity):
dt = Reqired(date)
course = Required(Course,
columns=['course_name', 'semester'])


Teno
30.11.2017
11:02:03
class Faccab2(db.Entity):
facc_id = Required(int)
facc_serie = Required(str)
facc_cli_id = Required(int)
facc_fecha = Optional(date)
faclin2s = Set('Faclin2')
PrimaryKey(facc_id, facc_serie)
class Faclin2(db.Entity):
facl_facc_id = Required(int)
facl_facc_serie = Required(str)
facl_descripcion = Optional(str)
faccab2s = Required(Faccab2, columns=['facc_id', 'facc_serie'])
PrimaryKey(facl_facc_id, facl_facc_serie)
I get the error: pony.orm.dbapiprovider.OperationalError: (1054, "Unknown column 'faclin2.facc_id' in 'field list'")
Alexander/Matthew, Is there a better place to write my problem or is this the right channel? I wouldn't like to disturb you both


Alexander
30.11.2017
11:05:36
I think this is the right channel. Instead of
faccab2s = Required(Faccab2, columns=['facc_id', 'facc_serie'])
you probably need to write
faccab2s = Required(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
Because you need to specify not column of another table's primary key, but columns of current table which used to make a relationship

Teno
30.11.2017
11:06:33
I did it and this is the error: pony.orm.core.DBSchemaError: Column 'facl_facc_id' already exists in table 'faclin2'

Alexander
30.11.2017
11:07:01
Then you need to remove facl_facc_id attribute from entity definition

Google

Alexander
30.11.2017
11:07:37
Because it is not an independent attribute, but just a part of composte foreign key

Teno
30.11.2017
11:08:05
and then I have to remove the primarykey attribute, right?
If I would remove these attribute, I have to remove the primarykey attribute and then I get an error about the 'id primary key'

Alexander
30.11.2017
11:10:37
You probably just need to define it as a single attribute:
class Faclin2(db.Entity):
faccab2s = PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])

Teno
30.11.2017
11:11:38
I tried it and: pony.orm.core.ERDiagramError: Reverse attribute for Faccab2.faclin2s not found
sorry, this error: pony.orm.dbapiprovider.OperationalError: (1054, "Unknown column 'faclin2.id' in 'field list'")
Try to fiend id primary key

Alexander
30.11.2017
11:13:20
This error Unknown column 'faclin2.id' in 'field list probably appeared if you define Faclin2 entity without any PrimaryKey, and it was added automatically
You need to define primary key manually in way as I desribed here
You probably just need to define it as a single attribute:
class Faclin2(db.Entity):
faccab2s = PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])

Teno
30.11.2017
11:14:51
Yes, I did it and I get the last error: pony.orm.dbapiprovider.OperationalError: (1054, "Unknown column 'faclin2.id' in 'field list'")

Alexander
30.11.2017
11:16:38
Can you show again Faclin2 definition with which you have got that last error?


Teno
30.11.2017
11:17:24
class Faclin2(db.Entity):
facl_descripcion = Optional(str)
PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
MariaDB [clp_pruebas2]> describe faclin2;
+------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| facl_facc_serie | varchar(10) | NO | PRI | NULL | |
| facl_facc_id | int(11) | NO | PRI | NULL | |
| facl_alb_id | bigint(20) | NO | PRI | 0 | |
| facl_numlinea | int(11) | NO | PRI | 0 | |
| facl_fecha | date | YES | | NULL | |
| facl_codarticulo | varchar(13) | YES | | NULL | |
| facl_descripcion | varchar(54) | YES | | NULL | |
| facl_cantidad | float(9,3) | YES | | NULL | |
| facl_preciocoste | decimal(11,4) | YES | | NULL | |
| facl_precio | decimal(11,4) | YES | | NULL | |
| facl_dto | float(4,2) | YES | | 0.00 | |
| facl_importe | float(10,3) | YES | | 0.000 | |
| facl_iva | tinyint(4) | NO | | 21 | |
| facl_talla | char(2) | YES | | NULL | |
| facl_color | char(2) | YES | | NULL | |
| createdAt | timestamp | YES | | NULL | |
| updatedAt | timestamp | YES | | NULL | |
+------------------+---------------+------+-----+---------+-------+


Alexander
30.11.2017
11:22:30
Instead of
PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
you need
faccab2s = PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
You need to define a PrimaryKey attribute with attribute name

Teno
30.11.2017
11:24:01
pony.orm.core.ERDiagramError: Reverse attribute for Faclin2.faccab2s not found

Alexander
30.11.2017
11:24:33
add
class Faccab2(db.Entity):
...
faclin2s = Set('Faclin2')

Teno
30.11.2017
11:24:46
ups, I forgot it
Yes!! I don't get any error now!

Google

Alexander
30.11.2017
11:25:21
Cool :)

Teno
30.11.2017
11:25:27
I'm going to make some test.
Thank you very very much!!

Alexander
30.11.2017
11:25:39
Sure

Teno
30.11.2017
11:25:57
It's incredible your support !! and your software!!

Alexander
30.11.2017
11:26:06
?


Teno
30.11.2017
15:37:17
Hi guys. I have been doing some tests and I can't get all the rows for the details table from the master object. The summary:
I have two models:
class Faccab2(db.Entity):
facc_id = Required(int)
facc_serie = Required(str)
facc_cli_id = Required(int)
facc_fecha = Optional(date)
faclin2s = Set('Faclin2')
PrimaryKey(facc_id, facc_serie)
class Faclin2(db.Entity):
facl_descripcion = Optional(str)
faccab2s = PrimaryKey(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
The Faclin2 table has many items from the Faccab2 (many-to-one).
When I run that code, I get the right sqls sentences in debug mode:
GET CONNECTION FROM THE LOCAL POOL
SELECT c.facc_id, c.facc_serie, c.facc_cli_id, c.facc_fecha
FROM faccab2 c
WHERE c.facc_id = '101'
AND c.facc_serie = 'PS17'
SELECT facl_descripcion, facl_facc_id, facl_facc_serie
FROM faclin2
WHERE facl_facc_id = %s
AND facl_facc_serie = %s
[101, u'PS17']
/*this sentence gets all the 3 rows in mysql console*/
But the problem is I’m only getting 1 out of 3 rows in the detail table (Faclin2) when I use the model:
facturas = select(c for c in Faccab2 if c.facc_id=='101' and c.facc_serie=='PS17')
for factura in facturas:
print len(factura.faclin2s) # 1
for linea in factura.faclin2s:
print linea.facl_descripcion # I only get one row, the last one
I think I'm not using well the query object. What am I doing wrong? How can I get all the detail rows?
Thank you in advance.


Alexander
30.11.2017
15:58:16
Your code looks correct. Are SQL queries you got in debug mode was from executing this code?

Teno
30.11.2017
15:58:44
Yes, they are

Alexander
30.11.2017
16:02:22
It looks strange. Maybe there is some problem with the register of letters? If you execute the query in mysql console, what values of facl_fac_serie do you get?
SELECT facl_facc_id, facl_facc_serie
FROM faclin2
WHERE facl_facc_id = 101
AND facl_facc_serie = 'PS17'
Maybe for some rows it is 'ps17' or something like that?

Teno
30.11.2017
16:04:02
+--------------+-----------------+
| facl_facc_id | facl_facc_serie |
+--------------+-----------------+
| 101 | PS17 |
| 101 | PS17 |
| 101 | PS17 |
+--------------+-----------------+
3 rows

Alexander
30.11.2017
16:05:03
Looks strange. By the way, if you know value of primary key, you can get factura object in a more smple way:
factura = Faccab2[101, 'PS17']
but it is irrelevant for this error.

Teno
30.11.2017
16:05:52
Thank you fro the information
MariaDB [clp_pruebas2]> sELECT facl_facc_id, facl_facc_serie, facl_descripcion FROM faclin2 WHERE facl_facc_id = 101 AND facl_facc_serie = 'PS17';
+--------------+-----------------+--------------------+
| facl_facc_id | facl_facc_serie | facl_descripcion |
+--------------+-----------------+--------------------+
| 101 | PS17 | BOLSA REGALO |
| 101 | PS17 | BOLSA MEDIANA |
| 101 | PS17 | BOLSA COMPLEMENTO |
+--------------+-----------------+--------------------+

Alexander
30.11.2017
16:07:36
Well, it is not strange
In model you specified that combination of facl_facc_id and facl_facc_serie is a primary key. But from the data this is not correct - you have multiple rows with the same values of facl_facc_id and facl_facc_serie. You need to specify correct primary key for Faclin2 model

Teno
30.11.2017
16:09:58
ups, I understand. I have another field for the primary key in my database
the line number

Google

Alexander
30.11.2017
16:11:31
So the primary key is not composite?
Is the line number unique?

Teno
30.11.2017
16:12:01
Yes but there is a missing field for the primary key in the detail table
the primary key in the detail table is facc_id, facc_serie, and facc_numlinea
I forgot to add the facc_numlinea to the model

Alexander
30.11.2017
16:14:47
Then you need to define the model something like:
class Faclin2(db.Entity):
facl_descripcion = Optional(str)
faccab2s = Required(Faccab2, columns=['facl_facc_id', 'facl_facc_serie'])
line_num = Required(int, column=' facl_numlinea')
PrimaryKey(faccab2s, line_num)
So three column facl_facc_id, facl_facc_serie and facl_numlinea will be composite PK

Teno
30.11.2017
16:15:41
Thank you very much, I was thinking about that
exactly
Alexander, you are a STAR! Please let me know if I can give you a hand in something (web, translations, documentation, ...)
Now it's working like a charm

Alexander
30.11.2017
16:21:15
Super :)
It would be helpful to check documentation for some typos and fix the stylistics of sentences, maybe you can do some pull request :)
The documentation is at docs.ponyorm.com, and the repository for it is https://github.com/ponyorm/pony-doc

Bonbot
30.11.2017
16:23:58

Teno
30.11.2017
16:24:55
Sure, I'll do it

Alexander
30.11.2017
16:25:04
Thanks in advance! :)

Matthew
03.12.2017
08:42:42
Are there any downsides to using pony with Python 3 now?

Alexander
03.12.2017
09:20:22
I think no

Yuri
03.12.2017
09:20:44
Why "Pony"?
I think it isn`t serious name for such tool as orm.