コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
14677 ビュー

Hi 

I am trying to get a related field value from database, but it showing column 'column_name' does not exist

When i try to find out the value of product_id or using join to find the common data between sale.order and product.product Model . but it showing column 'column_name' does not exist.

In sale.order model the field defination is like 

product_id = fields.Many2one('product.product', related='order_line.product_id', string='Product')

But when i try to join two table like below code to fetch all data as per product, like below code.

select coalesce(p.name,'Unassigned Product'), count(*) from sale_order o left join product_product p on o.product_id = p.id where o.state = 'sale' group by p.name;

It showing below error, 

column o.product_id does not exist
LINE 1: ... from sale_order o left join product_product p on o.product_...

When i try to get data from sale_order  table like below code.

select product_id from sale_order; 

It showing below error. 

column "product_id" does not exist

Can any one help me to get that value. 

アバター
破棄

without adding store=True in python code the related fields will not store into the Database by default

or

in xml you have give an attribute force_save="True"

著作者

I know that attribute, but this field is sale.order base field and no. of data also there. So i don't want to update that field. If i update that field it will not affect the past data. So any other option is there? Please tell me.

最善の回答

Try:

product_id = fields.Many2one(
'product.product',
related='order_line.product_id',
string='Product',
store=True,
)

The attribute store would add a column to Postgres. Otherwise, it is just a Python method which apply to a comodel table (in that case product.product) on a fly. 

アバター
破棄
関連投稿 返信 ビュー 活動
0
7月 24
1291
0
12月 21
2425
2
10月 16
6165
1
1月 16
4877
0
3月 15
4106