My Show Object:
class Show extends Realm.Object { }
Show.schema = {
name: 'Show',
primaryKey: 'showId',
properties: {
showId: 'int',
showName:{ type: 'string', default: '' },
episodes:{ type: 'int[]', default: [] },
}
};
How then can I search the Show objects via the episodes property?
I have already search here and there and tried:
.filtered('episodes == $0',12345)
.filtered('episodes IN $0',12345)
but nothing works.
IN predicates aren't yet supported, however, there are a couple of workarounds:
Property Array Contains Value
If you want to know if an array property on your Realm object contains one or more values, you can't use primitive values like int[] in your example. If instead you create an Episode schema with an id property, you can then do a filtered('episodes.id == $0', 12345).
Scalar Property in Array
This can be done by mapping and joining a set of predicates until IN is supported which looks something like the following psuedocode:
.filterted([1,2,3].map(id => 'property == id').join(' OR '))
Related
I have two arrays. I am trying to pluck out a property from one array and use it to find the value of another property in the other way. How to do this? Let me explain:
I have an array of objects that looks like so:
languageCodes:
{
"code1234char3": "mdr",
"name": "Mandar",
},
{
"code1234char3": "man",
"name": "Mandingo",
},
{
// etc...
},
I have another array of objects that looks like so:
divisionLanguages:
[
{
p_uID: 1,
nameLang3Char: 'mdr',
},
{
p_uID: 2,
nameLang3Char: 'man'
},
{
// etc..
}
]
I have a Vue template with an unordered list like so:
<ul v-for="x in divisionLanguages" :key="x.p_uID">
<li>Name: FOO
<li>Language: {{x.nameLang3Char}} - XXX</li> <--how to get 'name' value from 'languageCodes' and place here?
</ul>
Expected output should be:
Name: FOO
Language: mdr - Mandar
Name: BAR
Language: man - Mandingo
I tried to do something like in Vue SFC template (but did not work):
<li>Language: {{ languageName(x.nameLanguage3Char) }}</li>
...
methods: {
languageName(nameLanguage3Char) {
const name = this.divisionLanguages.filter(x => x.code6392char3 === nameLanguage3Char)
return name.name
}
I hope this makes sense of what I am trying to do.
Update: Thanks to #kellen in the comments, I change from filte() to find() like so:
languageName(nameLang3Char) {
const languageName = this.languageCodes.find(
x => x.code1234char3 == nameLang3Char
)
return languageName
},
and in I did:
<li>Language: {{ languageName(x.nameLang3Char).name }}</li>
and it works...but I get error in console:
Error in render: "TypeError: Cannot read property 'name' of undefined"
Have you tried combining these arrays before rendering them? If you were able to combine both objects before creating that list, that would make your life easier. Another thing I noticed is you're using filter, when find might be a better option to return a single value rather than an array. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
I'm adding a list called 'tourlocation' to my Keystone 5 project. In my mongo database my tourlocations collection has an object called 'coordinates', with two values: 'lat' and 'long'. Example:
"coordinates" : {
"lat" : 53.343761,
"long" : -6.24953
},
In the previous version of keystone, I could define my tourlocation list coordinates object like this:
coordinates: {
lat: {
type: Number,
noedit: true
},
long: {
type: Number,
noedit: true
}
Now unfortunately, when I try to define the list this way it gives the error: The 'tourlocation.coordinates' field doesn't specify a valid type. (tourlocation.coordinates.type is undefined)'
Is there any way to represent objects in keystone 5?
#Alex Hughes I believe your error says "type" which you may need to add it like this
keystone.createList('User', {
fields: {
name: { type: Text }, // Look at the type "Text" even in the MongoDB you can choose the type but it will be better to choose it here from the beginning.
email: { type: Text },
},
});
Note that noedit: true is not supported in version 5 of KeystoneJS.
For more info look at this page https://www.keystonejs.com/blog/field-types#core-field-types
I am trying to access my realm object by the number parameter. Can I use a rowID as a filter for my query, or is there another way to query a value based off the parameter?
Here is my realm object
class Hole extends Realm.Object {}
Hole.schema = {
name: 'Hole',
properties: {
number: 'int',
fullStroke: 'int',
halfStroke: 'int',
puts: 'int',
firstPutDistance: 'int',
penalties: 'int',
fairway: 'string'
},
};
Here is my query within the renderRow method.
{realm.objects('Hole').filtered('number = {realRowID}').fullStroke}
String interpolation should be `id == ${i}` (Use backtick and ${}). Your query should be:
realm.objects('Hole').filtered(`number = ${realmRowID}`)
Queries return Results object. Results is similar to Array. Results is a container that contains the objects of query results. So Results doesn't have fullStroke property because it isn't Hole object. So you should retrieve an element from Results first.
For example use [0] to retrieve first element as same as Array
realm.objects('Hole').filtered(`number = ${realmRowID}`)[0].fullStroke
See also https://realm.io/docs/react-native/latest/#queries
Basically, without knowing before hand what the resulting structure of a query might be, I'd like to query the database, and return a structure like this (json-y)
// Rows
[
// Row 1
[
{ ColumnName: "id", Value: 1, Type: int },
{ ColumnName: "name", Value: "batman", Type: string },
...
],
// Row 2
[
{ ColumnName: "id", Value: 2, Type: int },
{ ColumnName: "name", Value: "superman", Type: string },
...
]
]
Is there a way to get the Type for a Column using package database/sql in golang?
I'm suspecting that what I want to do is
make an array of interface{} the size of Column(),
then for each column determine it's type,
then fill the array with a pointer to that type,
and then pass the array to Scan()
Which is a little like this code example from sqlx, but without first knowing the Struct that the data would be populating.
You should be able to do it this way:
func printRows(rows *sql.Rows){
colTypes, err := rows.ColumnTypes()
for _,s := range colTypes {
log.Println("cols type:", s.DatabaseTypeName());
}
}
Using database/sql? No (as far as I know).
But you can use this code for arbitrary queries. And json.Marshall() from the json package will use reflection to determine the right way to print a value, so you could have a structure like this:
type Column struct {
ColumnName string
ColumnValue interface{}
ColumnType string
}
And then use reflect.TypeOf(someVariable).String() to get the type for ColumnType.
So I have a store
Ext.define('APN.store.BackupShow', {
extend: 'Ext.data.Store',
requires: [
'APN.model.ScheduledShow'
],
config: {
model: 'APN.model.ScheduledShow',
proxy: {
type: 'ajax',
url: '',
reader: {
type: 'xml',
record: 'item',
rootProperty: 'xml'
}
}
},
getShow: function () {
if (this.getData().length greater 1) # by some reason stackoverflow didn't allow me to put greater sign in here;
return null;
// Copy field data across as wrong field is popped.
this.getAt(0).set("listimage", this.getAt(0).get("onairimage"));
this.getAt(0).set("isbackup", "true");
return this.getAt(0);
}
});
And when I'm trying to call the first element of the store I get undefined, however the element exists in the store:
(0) console.log(backupShowStore);
(1) console.log(backupShowStore.data);
(2) console.log(backupShowStore.getData().all);
(3) console.log(backupShowStore.getData().all.length);
(4) console.log(backupShowStore.getData().all.getAt(0));
I got back:
(1)
Class
_data: Class
_model: function () {
_modelDefaults: objectClass
_proxy: Class
_remoteFilter: false
_remoteSort: false
_storeId: "backupShow"
_totalCount: null
config: objectClass
data: Class
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
0: Class
_data: Object
data: Object
bufferingProgress: null
contentlink: null
description: null
facebooklink: "http://www.facebook.com/mixmelbourne"
id: "ext-record-45"
isbackup: null
listimage: null
onairimage: "http://arntrnassets.mediaspanonline.com/radio/mxm/53808/on-air-default_v3.png"
showbody: "Melbourne's widest variety from 2K to today, Mix101.1 with Chrissie & Jane waking up Melbourne weekdays from 6am."
showbyline: "The widest variety from 2K to today"
showcontentxml: null
showemail: null
showname: "Mix 101.1"
showschedule: null
smallimage: null
title: null
twittername: "mixmelbourne"
__proto__: Object
id: "ext-record-45"
internalId: "ext-record-45"
modified: Object
phantom: true
raw: item
stores: Array[1]
__proto__: TemplateClass
length: 1
__proto__: Array[0]
(2)
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
config: objectClass
dirtyIndices: true
getKey: function (record) {
indices: Object
initConfig: function (){}
initialConfig: Object
items: Array[1]
keys: Array[1]
length: 1
map: Object
__proto__: TemplateClass
(3)
Array[1]
0: Class
length: 1
__proto__: Array[0]
(4)
0
(5)
Uncaught TypeError: Object [object Array] has no method 'getAt'
Which is understandable for (5) as array doesn't have method getAt, however the store doesn't have any items and that is indicated by (4) where the array of getData elements equals to 0...
Am very confused at this point of time with Sencha Touch Framework and how to get the first element of an array of elements
Why not just use the Ext.data.Store.first() method.
I have found I am typically a happier developer when I use the methods provided by the api. On the rare occasion that I need something not provided I will navigate the Sencha Objects myself but I really try not to.
Let me know if and why that solution might not work and I'll try to find something else for you.