小编Anu*_*TBE的帖子

在CakePHP 3中按相关模型的条件查找

我有两个表orderssub_orders.他们的关系是

$orders->hasMany('SubOrders', [
   'foreignKey' => 'order_id'
]);
Run Code Online (Sandbox Code Playgroud)

两个表都有invoice_nosub_invoiceorderssub_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)

cakephp model-associations cakephp-3.2

3
推荐指数
1
解决办法
2274
查看次数

Angular 6路由重定向

我是新手Angular并编写了第一个Angular管理仪表板应用程序.

我必须设置两个布局

  1. 用于身份验证,如登录,注销,忘记密码等
  2. 管理员仪表板将在登录后到来

为此我设置了两个布局组件

  1. 管理布局
  2. AUTH-布局

并将所有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)

angular-routing angular

3
推荐指数
1
解决办法
2万
查看次数

auto_now 字段未通过使用 filter() 进行更新

我在用着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 django-models

3
推荐指数
1
解决办法
1996
查看次数

DRF request.data没有属性_mutable

我正在使用 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

3
推荐指数
1
解决办法
2508
查看次数

无服务器框架 TypeError:e 不是函数

我用来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)

serverless-framework serverless

3
推荐指数
2
解决办法
9830
查看次数

CakePHP 3:未知方法

我正在模型中创建一个函数来查找所有相关服务.

功能 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'

我在做什么事情有什么不对吗?

cakephp model cakephp-3.0

2
推荐指数
1
解决办法
2954
查看次数

在cakephp 3中将同一个表与两个外键相关联

我有一张表match_schedules存储两个之间的匹配teams.有表teams存储团队信息.

match_schedules

+-----+---------+---------+-------+-------+
| id  | team_a  | team_b  | date  | venue |
+-----+---------+---------+-------+-------+
Run Code Online (Sandbox Code Playgroud)

由于我有两列team_ateam_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)

但这不起作用.

cakephp model-associations cakephp-3.2

2
推荐指数
1
解决办法
1795
查看次数

在ajax响应中打印json对象

我正在使用 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)

现在我只需要打印消息。如何打印/使用数组对象中的单个对象?

jquery json

2
推荐指数
1
解决办法
6178
查看次数

ValidationError:在 Django 中不是有效的 UUID

我在用着Django 2.0

我有一张Note桌子和StarredNotes一张桌子。

最初,没有id字段,因为它是默认添加的数据Django类型integer

现在我已将模型中的数据类型更改idUUID

模型.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)

django django-urls django-2.0

2
推荐指数
1
解决办法
7928
查看次数

Angular 6中的Observable <string>类型中不存在属性'publish'

我正在写我的第一个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导入但导入显示未使用.我也尝试了导入示例中的导入,但仍然得到相同的错误.

rxjs angular angular6

2
推荐指数
1
解决办法
954
查看次数