我使用 version 在 Django 中启动了新项目2.2,它具有新的约束唯一约束,这与unique_together相同还是有任何其他差异?
django django-models django-queryset django-managers python-3.6
我需要findAll()在Doctrine中使用Array获取数据库中的所有记录,My Query就是这样的东西
$result = $this->getDoctrine()
->getRepository('CoreBundle:Categories')
->findAll(\Doctrine\ORM\Query::HYDRATE_ARRAY);
Run Code Online (Sandbox Code Playgroud)
即使将水化模式设置为HYDRATE_ARRAY,我也会将结果作为对象
array:4 [?
0 => Categories {#323 ?}
1 => Categories {#326 ?}
2 => Categories {#329 ?}
3 => Categories {#332 ?}
]
Run Code Online (Sandbox Code Playgroud)
我犯了什么错误?
我是新手phoenix framework,让我说我有一个类似跟随变更集的模型
schema "users" do
field :name, :string
field :email, :string
field :countryCode, :string
field :phone, :string
end
def changeset_user_register(struct, params \\%{}) do
struct
|> cast(params, [:name, :email, :countryCode, :phone])
|> validate_required(:name, [message: "Name Must Not Be Empty"])
|> validate_required(:countryCode, [message: "countryCode Must Not Be Empty"])
|> validate_required(:phone, [message: "Phone Number Must Not Be Empty"])
|> valid_phone_number
end
Run Code Online (Sandbox Code Playgroud)
表格中的参数看起来像 %{name: 'elixir', countryCode: 'IN', phone: '97989*****'}
我目前正在使用ex_phone_number来验证电话号码,我的自定义验证器valid_phone_number如下所示
defp valid_phone_number(struct) do
countryCode = get_field(struct, :countryCode) #get_field …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用phoenix框架和mongodb作为数据库,所以我运行以下命令来开始
mix phoenix.new helloworld --database mongodb
Run Code Online (Sandbox Code Playgroud)
我的mix.exs文件看起来像这样:
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:mongodb_ecto, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"}]
end
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时mix deps.get,我收到以下错误:
Failed to use "ecto" (versions 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4) because
mongodb_ecto (versions 0.1.0 to 0.1.2) requires ~> 1.0
phoenix_ecto (version 3.0.1) requires ~> 2.0
Failed to use "ecto" (versions …Run Code Online (Sandbox Code Playgroud) 假设我有一个像follow这样的功能。
import NetworkService from './services';
async function sendAPIRequest(data: any){
// validations
const service = new NetworkService();
await service.call(data)
}
Run Code Online (Sandbox Code Playgroud)
我的测试看起来像这样,它使用了 mocha、chai、sinon。
describe('sendAPIRequest', function(){
it('make api', async function(){
// trying to mock Network service like below
const serviceMock = sinon.createStubInstance(NetworkService);
await sendAPIRequest({name: 'foobar'})
});
});
Run Code Online (Sandbox Code Playgroud)
但我收到了类似的错误
错误:预期在对象上存根方法,但没有找到
NetworkService.测试时如何模拟我的sendAPIRequest.
elixir ×2
django ×1
doctrine-orm ×1
ecto ×1
express ×1
mocking ×1
mongodb ×1
python-3.6 ×1
sinon ×1
symfony ×1
typescript ×1
unit-testing ×1