Unknown column in field list generating from fixture file - silverstripe

I've created a fixture file to test an element that I've created using Dna Design's Silverstripe Elemental package and Silverstripe seems to insist that the has_many relationship 'Elements' in ElementalArea doesn't exist.
SilverStripe\ORM\Connect\DatabaseException: Couldn't run query:
INSERT INTO "ElementalArea"
("Elements")
VALUES
(?)
Unknown column 'Elements' in 'field list'
I have the fixture file:
---
MyElement:
my-element:
...
ElementalArea:
elemental-area:
Elements: =>MyElement.my-element
I've tried running sake /dev/build "flush=all" and clearing /tmp/sivlerstripe-cache... with no luck

In Silverstripe 4 the Elemental module is namespaced. In our fixture yml file we must provide the full namespaced path for ElementalArea.
Also, on a has many relationship we can set the relationship on the has one side (the Element):
DNADesign\Elemental\Models\ElementalArea:
elemental-area:
Title: 'Area 1'
DNADesign\Elemental\Tests\Src\TestPage:
page1:
Title: 'Page 1'
URLSegment: 'test-page'
ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.elemental-area
MyElement:
my-element:
Title: 'Element 1'
ParentID: =>DNADesign\Elemental\Models\ElementalArea.elemental-area

Related

Can't add a field to a model in Symfony, bin/console crashes

I'm working with Sylius framework. I'm following the guide to customize models.
I am trying to add a field notice to a model Taxon which is already overridden in my project. For that, I added the field description to Taxon.orm.yml of the model:
MyProject\Bundle\ShopBundle\Entity\Taxon:
type: entity
table: sylius_taxon
# {Relationships code...}
fields:
# {Some existing fields...}
notice:
type: text
nullable: true
I also added a field, a getter and a setter to the overriding Taxon class.
Then I'm trying to run bin/console doctrine:migrations:diff, but when I run bin/console even without any arguments, it crashes with the following exception:
[Doctrine\DBAL\Exception\InvalidFieldNameException]
An exception occurred while executing 'SELECT s0_.code AS code_0, s0_.tree_left AS tree_left_1, s0_.tree_right AS tree_right_2, s0_.tree_level AS tree_level_3, s0_.position AS position_4, s0_.id AS id_5, s0_
.created_at AS created_at_6, s0_.updated_at AS updated_at_7, s0_.enabled AS enabled_8, s0_.default_markup AS default_markup_9, s0_.notice AS notice_10, s0_.tree_root AS tree_root_11, s0_.parent_id AS parent_
id_12 FROM sylius_taxon s0_ WHERE s0_.parent_id IS NULL ORDER BY s0_.tree_left ASC':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'`
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'`
[PDOException]
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.notice' in 'field list'
If I remove the changes to Taxon.orm.yml then bin/console works again. What is missing in my changes?
One of my bundles' configruation contained that model's repository, that's it. I temporarily deleted the bundle's configuration from config.yml, and bin/console worked.
When you add new field you should doctrine:schema:update

Property 'first' does not exist on type 'FirebaseListObservable<any[]>'

I am using ionic 2
I installed angular fire2
Version: "angularfire2": "^2.0.0-beta.7-pre",
I am getting this err
Property 'first' does not exist on type 'FirebaseListObservable<any[]>'
I remove my nodemodules.
again npm install
Still getting same err.
How can I fix this issue.
if you want to get the first element in your FirebaseListObservable< any[]> in html file, then you can do like following:
<div *ngFor="let item of items | async | slice:0:1">{{item}}</div>
where "items" is FirebaseListObservable< any[]>
if you want to get the first element in your .ts file, then you should do like this:
firstItem: any;
...
this.items.subscribe((allItems) => {this.firstItem = allItems[0]});

symfony2 - createQueryBuilder Doctrine build query with first capital letter

I' following a symfony2 tutorial and I've problems with one step.
Tutorial link: http://intelligentbee.com/blog/2013/08/12/symfony2-jobeet-day-6-more-with-the-model/
I'm in 'Refactoring' step. I've one this 3 steps:
1- I've correctly modified /src/Ibw/JobeetBundle/Resources/config/doctrine/Job.orm.yml file specifiying the repository
2- I've run the command: php app/console doctrine:generate:entities IbwJobeetBundle
3- And I've added the specified tutorial function por JobRepository.php
$qb = $this->createQueryBuilder('j')
->where('j.expires_at > :date')
->setParameter('date', date('Y-m-d H:i:s', time()))
->orderBy('j.expires_at', 'DESC');
BUT when I refresh my code I get this error:
An exception occurred while executing 'SELECT j0_.id AS id0, j0_.type
AS type1, j0_.company AS company2, j0_.logo AS logo3, j0_.url AS url4,
j0_.position AS position5, j0_.location AS location6, j0_.description
AS description7, j0_.how_to_apply AS how_to_apply8, j0_.token AS
token9, j0_.is_public AS is_public10, j0_.is_activated AS
is_activated11, j0_.email AS email12, j0_.expires_at AS expires_at13,
j0_.created_at AS created_at14, j0_.updated_at AS updated_at15,
j0_.category_id AS category_id16 FROM Job j0_ WHERE j0_.expires_at > ?
ORDER BY j0_.expires_at DESC' with params ["2016-03-17 15:47:19"]:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'jobeet.Job'
doesn't exist
In the symfony profiler I can see the full query:
SELECT j0_.id AS id0, j0_.type AS type1, j0_.company AS company2,
j0_.logo AS logo3, j0_.url AS url4, j0_.position AS position5,
j0_.location AS location6, j0_.description AS description7,
j0_.how_to_apply AS how_to_apply8, j0_.token AS token9, j0_.is_public
AS is_public10, j0_.is_activated AS is_activated11, j0_.email AS
email12, j0_.expires_at AS expires_at13, j0_.created_at AS
created_at14, j0_.updated_at AS updated_at15, j0_.category_id AS
category_id16 FROM Job j0_ WHERE j0_.expires_at > '2016-03-17
15:47:19' ORDER BY j0_.expires_at DESC
the table name it's in uppercase! 'Job', not 'job'
Any can help me, please?
You can try by modifying the entity definition in Job.orm.yml by adding the table attribute:
IbwJobeetBundleEntityJob:
type: entity
table: job
repositoryClass: IbwJobeetBundleRepositoryJobRepository

How can I ask Riak 1.4 to index and then be able to search my document based on properties of embedded document?

Working with Riak 1.4.7
I have a document that has a property that is an array of embedded documents. Here is a sample of the document:
{"prospect":true, "name":"HzNUeioPYynsGdXL6iSFvQ",
"contact_email":"contact#HzNUeioPYynsGdXL6iSFvQ.gr",
"e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
{"store_url":"www.store2.url.com","display_name":"hello2 there"}]
}
The corresponding bucket has index enabled and works fine. For example, the following search command locate the object without problem:
search-cmd search index_name contact_email:contact#HzNUeioPYynsGdXL6iSFvQ.gr
The question here is how can I search by the store_url for example.
store_url is a property of an embedded document which, in turn, is an element of an array property of the main document.
1) Do I have to specify a custom schema file in order for the index to index these properties?
2) Do I have to query using some kind of special syntax?
The default JSON extractor should handle that case by joining all of the values in the array in a space separated list. Nested names are handled by joining them with an underscore. So in this case, the field e_shops_store_url would contain www.store.url.com www.store2.url.com. You can query that field normally.
I ran a quick example to demonstrate:
root#node1:~# search-cmd install searchtest
:: Installing Riak Search <--> KV hook on bucket 'searchtest'.
root#node1:~# curl 172.31.0.1:8098/buckets/searchtest/keys/test1 \
-XPUT -H"content-type:application/json" \
-d '{"prospect":true, "name":"HzNUeioPYynsGdXL6iSFvQ",
> "contact_email":"contact#HzNUeioPYynsGdXL6iSFvQ.gr",
> "e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
> {"store_url":"www.store2.url.com","display_name":"hello2 there"}]
> }'
root#node1:~# curl 172.31.0.1:8098/buckets/searchtest/keys/test2 \
-XPUT -H"content-type:application/json" \
-d '{"prospect":true, "name":"-HzNUeioPYynsGdXL6iSFvQ",
>"contact_email":"contact#-HzNUeioPYynsGdXL6iSFvQ.gr",
>"e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
> {"store_url":"www.store3.url.com","display_name":"hello3 there"}]
>}'
root#node1:~# search-cmd search-doc searchtest e_shops_store_url:www.store.url.com
:: Searching for 'e_shops_store_url:www.store.url.com' / '' in searchtest...
------------------------------
index/id: searchtest/test1
<<"contact_email">> => <<"contact#HzNUeioPYynsGdXL6iSFvQ.gr">>
<<"e_shops_display_name">> => <<"hello there hello2 there">>
<<"e_shops_store_url">> => <<"www.store.url.com www.store2.url.com">>
<<"name">> => <<"HzNUeioPYynsGdXL6iSFvQ">>
<<"prospect">> => <<"true">>
------------------------------
index/id: searchtest/test2
<<"contact_email">> => <<"contact#-HzNUeioPYynsGdXL6iSFvQ.gr">>
<<"e_shops_display_name">> => <<"hello there hello3 there">>
<<"e_shops_store_url">> => <<"www.store.url.com www.store3.url.com">>
<<"name">> => <<"-HzNUeioPYynsGdXL6iSFvQ">>
<<"prospect">> => <<"true">>
------------------------------
:: Found 2 results.
:: Maximum score "0.353553".

Import DateTime using Nemo/Alice bundle

My question is about this bundle: https://github.com/nelmio/alice in combination with Symfony2.
I have some fixture i want to load in my new website, and this bundle is great for that. I created some YML files and consider the following YML as my fixturedata:
DateTime (local):
news-date-1:
__construct: ['2014-07-01']
Stef\BVBundle\Entity\Blog:
StefBVBundle-Blog-1:
title: 'A day with blah'
blog: 'e5645646'
image: 'beach.jpg'
author: 'dsyph3r'
tags: 'symfony2, php, paradise, symblog'
created: #news-date-1
updated: #news-date-1
StefBVBundle-Blog-2:
id: 1
title: 'meeeh'
author: dsyph3r
blog: '5rw5425'
image: beach.jpg
tags: 'symfony2, php, paradise, symblog'
created: '2014-07-01T00:00:00+0200'
updated: '2014-07-01T00:00:00+0200'
The one labelled with 'StefBVBundle-Blog-1' works like a charm, it knows 'created' and 'updated' are \DateTime values.
But 'StefBVBundle-Blog-2' causes an error, because the Nemo/Alice bundle consider it as a string, instead of a DateTime. Is it possible to do the DateTime-part inline?
PHP Expressions inside <( )> are simply passed to Doctrine, so this will do the work :
Stef\BVBundle\Entity\Blog:
StefBVBundle-Blog-2:
created: <(new \DateTime('2014-02-02'))>
Regarding the doc of Faker library, you have to specify a DateTime instance, or DateTimeBetween with no time-laps if you want an exact date.
Your code, with correction:
DateTime (local):
news-date-1:
__construct: ['2014-07-01']
Stef\BVBundle\Entity\Blog:
StefBVBundle-Blog-1:
title: 'A day with blah'
blog: 'e5645646'
image: 'beach.jpg'
author: 'dsyph3r'
tags: 'symfony2, php, paradise, symblog'
created: #news-date-1
updated: #news-date-1
StefBVBundle-Blog-2:
id: 1
title: 'meeeh'
author: dsyph3r
blog: '5rw5425'
image: beach.jpg
tags: 'symfony2, php, paradise, symblog'
created: <dateTimeBetween('0 days', '2014-07-01T00:00:00+0200')>
updated: <dateTimeBetween('0 days', '2014-07-01T00:00:00+0200')>
Didn't try, but should work.

Resources