I have a subclass called TreeFolderObject. One of the column headings is called "parent" and is a pointer field. It points to other another object in the same class. Here is the stripped down code I am using to attempt to read data from this structure:
var TreeFolderObject = Parse.Object.extend('TreeFolderObject');
var folderQuery = new Parse.Query(TreeFolderObject);
folderQuery.include("parent");
folderQuery.find().then(function(results) {
for (i in results) {
treeData.push({
title: results[i].get('folderName'),
objectId: results[i].id,
parent: results[i].get("parent")
});
console.log(results[i].get("parent").get("folderName") );
}
},
function(error) {
console.log("failed, with error code: " + error);
}
);
The console line reports the following output:
Uncaught TypeError: Cannot read property 'get' of undefined
I have also tried shortening the console.log line to just:
console.log(results[i].get("parent") );
and this reports the following:
undefined
index.html:100
ParseObjectSubclass {className: "TreeFolderObject", _objCount: 32, id: "oq5o2zFqIM"}
index.html:100 ParseObjectSubclass {className: "TreeFolderObject", _objCount: 24, id: "oq5o2zFqIM"}
index.html:100 ParseObjectSubclass {className: "TreeFolderObject", _objCount: 41, id: "oq5o2zFqIM"}
etc
This indicates that the browser client is obtaining the information I am after. I just can't work out how to get the data "out", if that makes sense.
Ultimately, I want to identify the parent object of each object so I can iterate through the class.
What I am doing wrong? I have tried searching here and on the web in general and there are a lot of very similar questions. This is obviously a confusing topic. I just can't work it out though and any help would be much appreciated. How do I get the console to print out the folderName property of the parent object?
Here's a screenshot of the parse control panel, if that helps:
enter image description here
Add "var" in front of i like this
var TreeFolderObject = Parse.Object.extend('TreeFolderObject');
var folderQuery = new Parse.Query(TreeFolderObject);
folderQuery.include("parent");
folderQuery.find().then(function(results) {
for (var i in results) {
treeData.push({
title: results[i].get('folderName'),
objectId: results[i].id,
parent: results[i].get("parent")
});
console.log(results[i].get("parent").get("folderName") );
}
},
function(error) {
console.log("failed, with error code: " + error);
}
);
Answering my own question here:
I eventually discovered the answer, and its got nothing to do with labeling i as a var, or the fact that I'm querying the same class. The solution is to put a condition line in the query. In other words, insert this after the first two lines of the code I posted earlier:
folderQuery.exists("parent");
In my case every object in the class, apart from one, has a parent, so this works fine. What I don't understand is why it should be necessary to put a condition on the query at all, if I'm intending to query the entire class.
I discovered the solution after browsing lots of parse pointer related questions on StackOverflow. No one else seems to have fallen into the exact same trap of leaving out the condition line, and eventually I realised that my parse query wasn't following the convention. If this realisation helps anyone else out there, I will be happy to have helped!
If anyone can help with an explanation as to why I need to put a condition line in, even though I'm querying the entire class, please let me know. In the meantime, I'm happy to have found this solution as it was holding up development of my project.
Related
I have to use the LOWER function in whereIn using knex.
I want to change the below line of code
whereIn("name", members);
If I do whereIn('LOWER("name")', members);, getting error as
Column LOWER("name") is not present.
I tried to use knex.raw but again not getting the correct syntax.
const roleMembers = await t("roles")
.select({ role_id: "id" }, "name")
.whereIn(t.raw("LOWER('name')"), members);
Error:
index.d.ts(1184, 5)
When I try to add await, syntax error goes away but when I execute this code I get the below error
error: LOWER(name) - syntax error at or near "LOWER"
I'm referring http://knexjs.org/#Builder-whereIn
We have whereRaw, Do we have a similar thing for whereIn? Need some help to fix this issue.
Note: I used all LOWER, lower, Lower.
knex.raw() can be used for the column component
knex('members').whereIn(knex.raw('Lower("name")'), members)
select * from `members` where Lower("name") in ('Tom', 'Dick', 'harry')
The final solution is below.
const roleMembers = await t("roles")
.select({ role_id: "id" }, "name")
.whereIn(t.raw('LOWER("name")') as any, members);
My changes to the original code are
Quotes: swapped " and '
lower, Lower and LOWER worked
Typescript error: added as any
Thanks Matt and Mikael for guidance.
I am trying to update a milestone to a task (and vice-versa). To do so, I update the data and set milestone: true and even remove the end just to be safe.
Here you can press the button and the point should visually update (its values do) but it doesn't and I am wondering if I'm doing something wrong or if it is not doable to begging with.
Please note that we get a highcharts-gantt.src.js:48256 Uncaught TypeError: Cannot read property 'animate' of undefined.
Also, you don't get this error when updating from task to milestone.
I'm assuming this may just have been overlooked by the devs and I can probably get a workaround if I post this as an issue on the repo but maybe I'm just doing this wrong to begin with (in some cases, you aren't supposed to update directly but instead use a setSomething function).
Edit
"
Workaround(s):
When updating point, set marker.symbol = null, demo: https://jsfiddle.net/BlackLabel/oyL24bvq/
Snippet:
chart.series[0].points[0].update({
...
marker: {
symbol: null
}
});
Destroy point.graphic before updating point, demo: https://jsfiddle.net/BlackLabel/35vyhqmz/
Snippet:
chart.series[0].points[0].graphic = chart.series[0].points[0].graphic.destroy();
"
(source: https://github.com/highcharts/highcharts/issues/11158)
"
Workaround(s):
When updating point, set marker.symbol = null, demo: https://jsfiddle.net/BlackLabel/oyL24bvq/ Snippet:
chart.series[0].points[0].update({
...
marker: {
symbol: null
}
});
Destroy point.graphic before updating point, demo: https://jsfiddle.net/BlackLabel/35vyhqmz/ Snippet:
chart.series[0].points[0].graphic = chart.series[0].points[0].graphic.destroy();
"
(source: https://github.com/highcharts/highcharts/issues/11158)
I have an existing DDB table which uses BillingMode: PROVISIONED and ProvisionedThroughput:{...}. I want to change it to use BillingMode: PAY_PER_REQUEST but when I do so I get the following error:
TypeError: Cannot read property 'ReadCapacityUnits' of undefined
The parameters I'm sending to the updateTable call are:
{
"TableName": "my-table-name",
"AttributeDefinitions": [
{
"AttributeType": "S",
"AttributeName": "name"
}
],
"BillingMode": "PAY_PER_REQUEST"
}
I also tried sending a ProvisionedThroughput field with the ReadCapacityUnits and WriteCapacityUnits in but this returned:
ValidationException: One or more parameter values were invalid: ProvisionedThroughput cannot be specified when BillingMode is PAY_PER_REQUEST
... which is what I would expect from reading the docs.
Any ideas what I'm doing wrong?
It turns out that this was my mistake... to answer the question, you send exactly what I posted above, or just
{
"TableName": "my-table-name",
"BillingMode": "PAY_PER_REQUEST"
}
... the "AttributeDefinitions" is unneeded as Nadav Har'El pointed out.
The problem was that in my lambda version I was building up the object to send based on what had changed and including ProvisionedThroughput: undefined which caused the SDK to try and validate this object. I did not see the problem for a long time because console.log(JSON.stringify()) removes any keys whose value is undefined. To illustrate this another way:
$ node
> var a = {foo:1, bar:undefined}
undefined
> a
{ foo: 1, bar: undefined }
> console.log(JSON.stringify(a))
{"foo":1}
undefined
This should work for you, in https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/WorkingWithTables.Basics.html there is an example:
aws dynamodb update-table --table-name Music --billing-mode PAY_PER_REQUEST
The "AttributeDefinitions" part in your request seems superfluous, did you try without it?
I came to this question because I had a similar problem.
Turns out I was using CDK watchful which kind of requires PROVISIONING MODE, with readCapacity and writeCapacity defined for the dynamo table. Once I'd done that, the cdk diff, cdk synth were happy again.
I asked a question yesterday, but I've kept going with it. Instead of calling next() and passing an an Error object, I worked out what it was doing, and tried to copy it. Now, when someone logs in and it fails, I do this:
res.render("pages/home",
{
flash:{"danger":["Login failed. Please enter your details and try again."]},
body:{},
section:"home",
locals : { userId : req.body.email }
}
This does exactly the same thing as the old code. I step through it, and I can see that the locals object contains a property called userId, with the value I expect. In the Jade template, I have this:
p it's #{typeof(userId)}
if(typeof(userId) != 'undefined')
p Welcome #{userId}
input(type='text', name='email', id="inputEmail", placeholder="Email", value="#{userId}")
else
input(type='text', name='email', id="inputEmail", placeholder="Email", value="")
This always renders as 'it's undefined' and then an empty text box. I have read several questions on this, and as far as I can see, they all say the same thing: if I set locals to be a JSON object, I can access it's properties by this syntax, but it does not work.
What am I doing wrong ?
You might first need to better understand how locals object actually work.
On the server-side, doing this:
res.render('view', { property: 'value' } );
would make property available in your views like so:
div Value = #{property}
You can also do the following to have the same effect:
res.locals.property = 'value';
res.render('views');
Note the usage of locals object. More info
Coming back to your issue, since you have
res.render("pages/home", { locals: { userId : req.body.email } })
to access userId in this case you would do:
p Welcome #{locals.userId}
So I'm guess you're confusing the two approaches ending up using locals object the wrong way.
OK - turns out that 'locals' doesn't mean anything any more. Leaving my code as it is, I needed to access 'locals.userId', but I could have just set the value of 'userId' and not had the 'locals' object at all.
We see this occasionally in web apps on Firefox. What triggers it, and how do we prevent it? It seems to happen sporadically and the error message yields no useful information about line locations.
A quick google search yielded this:
http://blowery.org/2008/02/28/object-cannot-be-created-in-this-context-code-9/
...check your code to see if you’re
trying to grab a reference to the
computed style on a null reference.
It appears to be connected with the Dojo framework.
Edit: Ha. Sorry I gave you your own blog as an answer. I guess I don't completely understand what you're asking for. If you want to avoid the error, you could use object checking before running the applicable code.
function isValidObject(someObject)
{
return typeof someObject != null;
}
var obj1 = "Hello World";
if(isValidObject(obj1))
{
//This code will run
}
if(isValidObject(ob2))
{
//This code will not run
}
Hope that's helpful.