我正在尝试:
sold_products.quantity * sold_products.sold_price
ExportInvoice::rightJoin('sold_products', 'sold_products.export_invoice_id', '=', 'export_invoices.id')
->select(
'sold_products.product_id',
DB::raw('sum(sold_price * quantity) as bam') // I want to use the mutator not sold_price
)
->groupBy('sold_products.product_id')
->get();
一切正常,并返回期望值。
我在SoldProducts.php model
中有一个变量,该变量附加到字段item_net_price
中。
我想使用item_net_price
而不是sold_price
(正如我在上面代码中的注释中所添加的那样。)
答案 0 :(得分:1)
使用setup(
name='app',
version=0.1,
description='Blog with CMS',
classifiers=[
"Programming Language :: Python",
"Framework :: Pylons",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application"
],
keywords="web services",
author='',
author_email='',
url='',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=['cornice', 'waitress'],
entry_points="""\
[paste.app_factory]
main=app:main
""",
paster_plugins=['pyramid']
)
代替leftJoin
,以便可以使用rightJoin
变异器。
SoldProduct
然后获取增幅器:
$product = SoldProduct::leftJoin('export_invoice', 'sold_products.export_invoice_id', '=', 'export_invoices.id')
->select(
'sold_products.product_id',
// You cannot use mutator in DB::raw, but you can do it like this:
DB::raw('sum(sold_price * 1.14 * quantity) as bam')
)
->groupBy('sold_products.product_id')
->get();