我有两个表orders和sub_orders.他们的关系是
$orders->hasMany('SubOrders', [
'foreignKey' => 'order_id'
]);
Run Code Online (Sandbox Code Playgroud)
两个表都有invoice_no和sub_invoice列orders和sub_orders分别.
我必须从orders表中找到包含相关sub_orders位置或者$trackingId匹配的记录Orders.invoice_noSubOrders.sub_invoice
$findOrder = $this->Orders->find('all', [
'conditions' => [
'OR' => [
'Orders.invoice_no' => $trackingId,
'SubOrders.sub_invoice' => $trackingId
]
],
'contain' => [
'SubOrders'
]
]);
Run Code Online (Sandbox Code Playgroud)
但这会给出错误
Column not found: 1054 Unknown column 'SubOrders.sub_invoice' in 'where clause'
Run Code Online (Sandbox Code Playgroud) 我是新手Angular并编写了第一个Angular管理仪表板应用程序.
我必须设置两个布局
为此我设置了两个布局组件
并将所有auth组件放入auth模块中
我的应用程序的目录结构是这样的
app
|- e2e
|- node_modules
|- src
|- app
|- auth (module)
|- login (component)
|- login.component.ts
|- login.component.html
|- register (component)
|- register.component.ts
|- register.component.html
|- auth.module.ts
|- dashboard (component for auth users)
|- dashboard.component.ts
|- dashboard.component.html
|- layouts ( directory)
|- admin-layout (component)
|- admin-layout.component.html
|- admin-layout.component.ts
|- admin-layout.module.ts
|- admin-layout.routing.ts
|- auth-layout (component)
|- auth-layout.component.html
|- auth-layout.component.ts
|- auth-layout.module.ts
|- auth-layout.routing.ts
|- app.component.html
|- …Run Code Online (Sandbox Code Playgroud) 我在用着Django 2.0。
我有一个像这样的模型
class MyModel(models.Model):
update_new = models.CharField(blank=True, max_length=200)
modified = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)
并使用更新模型数据Model Manager
class MyModelManager(models.Manager):
def get_queryset(self):
return MyModelQueryset(self.model, self._db)
def update_or_create(self, pk, **save_data):
record = MyModel.objects.filter(
pk=pk
)
if record.exists():
# setting field manually for testing
save_data['update_new'] = 'anuj'
uc = record.update(**save_data)
print(uc) # prints 1
return record.first(), True
record, created = self.get_queryset().get_or_create(
pk=pk
**save_data
)
return record, created
Run Code Online (Sandbox Code Playgroud)
这工作正常并且值已更新。但修改的字段不会更新。创建和修改字段中的值保持相同(创建记录时的时间戳)
我正在使用 Django 2.x 和 Django REST 框架。
我用来django-oauth-toolkit启用OAuth2身份验证、django-rest-auth登录和django-allauth用户注册。
我想在用户成功注册时在响应中生成访问令牌。为此,我使用自定义注册视图。
为此,我创建了一个函数 utils,例如
def generate_token(request, user):
# Get OAuth application to use
application_: Application = Application.objects.filter(
client_type=Application.CLIENT_CONFIDENTIAL,
authorization_grant_type=Application.GRANT_PASSWORD
).first()
if not application_:
raise Exception('No OAuth2 Application is setup')
auth_data = {
'username': user.username,
'password': password,
'grant_type': 'password',
'client_id': application_.client_id,
'client_secret': application_.client_secret
}
if request.data:
mutable = request.data._mutable
request.data._mutable = True
request.data.update(auth_data)
request.data._mutable = mutable
if request.POST:
mutable = request.POST._mutable
request.POST._mutable = True
request.POST.update(auth_data)
request.POST._mutable …Run Code Online (Sandbox Code Playgroud) python django django-rest-framework django-rest-auth django-oauth
我用来serverless-framework在 AWS 中安排任务。
我的应用程序结构是
|- src
|- tasks
|- analytics.task.js
|- tasks.js
|- serverless.yml
Run Code Online (Sandbox Code Playgroud)
的内容analytics.task.js
module.exports.run = (event, context, callback) => {
console.log('Getting data...');
console.log('success');
};
Run Code Online (Sandbox Code Playgroud)
出于测试目的,从运行方法中删除了所有其他代码。
内容tasks.js
const analyticsTask = require('./src/tasks/analytics.task');
module.exports.analytics = analyticsTask.run();
Run Code Online (Sandbox Code Playgroud)
和内容serverless.yml
functions:
analyticsDataProcess:
handler: tasks.analytics
description: 'Send analytics data to the backend server'
events:
- schedule:
name: analytics-data-process-task
description: 'Send analytics data every minute'
rate: rate(1 minute)
enabled: true
Run Code Online (Sandbox Code Playgroud)
但是运行任务的时候却报错
{
"errorMessage": "e is not a function",
"errorType": "TypeError",
"stackTrace": …Run Code Online (Sandbox Code Playgroud) 我正在模型中创建一个函数来查找所有相关服务.
功能 ServiceCategory.php
class ServiceCategory extends Entity
{
public function relatedServices($id)
{
return $this->find('all', [
'conditions' => [
'where' => [
'id !=' => $id
],
'limit' => 5
]
]);
}
}
Run Code Online (Sandbox Code Playgroud)
并且呼唤 ServiceCategoriesController.php
public function view($id = null)
{
$serviceCategory = $this->ServiceCategories->get($id, [
'contain' => ['Services']
]);
$relatedServices = $this->ServiceCategories->relatedServices($id);
$this->set('serviceCategory', $serviceCategory);
$this->set('relatedServices', $relatedServices);
$this->set('_serialize', ['serviceCategory']);
}
Run Code Online (Sandbox Code Playgroud)
但它给出了 Unknown method 'relatedServices'
我在做什么事情有什么不对吗?
我有一张表match_schedules存储两个之间的匹配teams.有表teams存储团队信息.
列match_schedules是
+-----+---------+---------+-------+-------+
| id | team_a | team_b | date | venue |
+-----+---------+---------+-------+-------+
Run Code Online (Sandbox Code Playgroud)
由于我有两列team_a和team_b引用teams表,我不能team_id在两列中使用外键.
现在,我想将这两列与teams表关联起来,以便我可以轻松地检索关联的数据
$matches = $this->MatchSchedules->find('all', [
'contain' => [
'Teams'
]
]);
Run Code Online (Sandbox Code Playgroud)
我在TeamsTable.php中试过这个
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_a',
'joinType' => 'INNER'
]);
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_b',
'joinType' => 'INNER'
]);
Run Code Online (Sandbox Code Playgroud)
在MatchSchedulesTable.php中
$this->hasMany('Teams', [
'foreignKey' => 'team_a'
]);
$this->hasMany('Teams', [
'foreignKey' => 'team_b'
]);
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
我正在使用 ajax 提交表单并打印响应代码。
这是 php 响应数组
$response['code'] = 401;
$response['message'] = 'Thank You';
$response['class'] = 'alert-success';
echo json_encode($response);
Run Code Online (Sandbox Code Playgroud)
这是 ajax 代码
$.ajax({
dataType: 'json',
type: 'POST',
url: '/sellers/php-page',
data: dataString,
cache: false,
success: function(d) {
console.log(d);
}
});
Run Code Online (Sandbox Code Playgroud)
console.log(d)给出的输出
Object { code: 401, message: "Thank You", class: "alert-success" }
Run Code Online (Sandbox Code Playgroud)
现在我只需要打印消息。如何打印/使用数组对象中的单个对象?
我在用着Django 2.0
我有一张Note桌子和StarredNotes一张桌子。
最初,没有id字段,因为它是默认添加的数据Django类型integer。
现在我已将模型中的数据类型更改id为UUID
模型.py
class Starred(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(User, on_delete=models.CASCADE)
note = models.ForeignKey(Note, on_delete=models.CASCADE)
objects = StarredManager()
class ColorLabels(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=100, unique=True)
value = models.CharField(max_length=100)
default = models.BooleanField(default=False)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title + '(' + self.value + ')'
Run Code Online (Sandbox Code Playgroud)
和views.py
class StarredNotes(ListView):
template_name = 'notes/starred.html'
model = …Run Code Online (Sandbox Code Playgroud) 我正在写我的第一个Angular申请表Angular 6.
我正在实现错误处理来处理单个地方的所有错误,为此,我正在遵循此媒体指南
根据stackblitz上的指南代码示例,我的NotificationService就像
import {Injectable} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs';
import {publish} from 'rxjs/operators';
@Injectable()
export class NotificationService {
private _notification: BehaviorSubject<string> = new BehaviorSubject(null);
readonly notification$: Observable<string> = this._notification.asObservable().publish().refCount();
constructor() {}
notify(message) {
this._notification.next(message);
setTimeout(() => this._notification.next(null), 5000);
}
}
Run Code Online (Sandbox Code Playgroud)
IDE正在给出错误 publish()
我甚publish至从rxjs/operators导入但导入显示未使用.我也尝试了导入示例中的导入,但仍然得到相同的错误.
cakephp ×3
django ×3
angular ×2
cakephp-3.2 ×2
angular6 ×1
cakephp-3.0 ×1
django-2.0 ×1
django-oauth ×1
django-urls ×1
jquery ×1
json ×1
model ×1
python ×1
rxjs ×1
serverless ×1