ExtJS 4 instantiated model has id set to 0 - extjs4

If I define an entity like this:
Ext.define('MyApp.model.Entity', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
} ]
});
And then instantiate it and output its id with:
var entity = Ext.create('MyApp.model.Entity');
console.log(entity.getId());
I'm getting 0 for the output. I would expect it to be undefined. Why is that?

There are two likely causes.
First, because you're using the name id for a field. Ext.data.Model has the idProperty config which defaults to id, defining the name of the field to be treated differently than the rest. The getId method is the equivalent of get(idProperty).
Second, because the type of id is int, in which case the default value for the field is 0 (unless you use the useNull field config).
I personally try to avoid using id for a model property because of its tendency to collide with pretty much everything. I've never had problems using something like recordId or something similar.

Related

Expected Name found { ; tring to find objects with specific field value

I'm trying to get familiar with graphql. So I have an entity called Car in BE. And I have only Cars exposed.
Now I'm trying to find all the cars from Cars, where year(launch) is certain say 2001. It's actually a variable. Now I think the following query should work.
query GetCars($y: String!) {
cars({ year: $y }) {
id
year
}
}
But it gives me error saying, Expected Name found {, it throws the error at the second dollar sign.
filters and where is also undefined.
Can anyone give me some hint to resolve this problem?
Using: GraphiQL
In cars({ year: $y}) the name of your argument is missing - arguments always need to have a name in GraphQL and the name of your arguments and their GraphQL type are defined in your schema.
Assuming your cars fields has an argument called year in your schema, you need to rewrite your query to: cars(year: $y).
Assuming your cars fields has a filter or something like that defined in the schema and that filter expects an input object type that has - maybe among others - a field year, you would write: cars(filter: { year: $y }).

"Cannot return null for non-nullable type: 'Person' within parent 'Messages' (/getMessages/sendBy)" in GraphQL SDL( aws appsync)

Iam new to graphql.Iam implementing a react-native app using aws appsync.Following is the code i have written in schema
type Messages {
id: ID!
createdAt: String!
updateAt: String!
text: String!
sendBy: Person!
#relation(name: "UserMessages")}
type Person {
id: ID!
createdAt: String!
updateAt: String!
name: String!
messages: [Messages!]!
#relation(name: "UserMessages")}
When i tried to query the sendBy value it is giving me an error saying
query getMessages{
getMessages(id : "a0546b5d-1faf-444c-b243-fab5e1f47d2d") {
id
text
sendBy {
name
}
}
}
{
"data": {
"getMessages": null
},
"errors": [
{
"path": [
"getMessages",
"sendBy"
],
"locations": null,
"message": "Cannot return null for non-nullable type: 'Person' within parent 'Messages' (/getMessages/sendBy)"
}
]
}
Am not understanding that error please help me.Thanks!! in Advance
This might sound silly, but still, developers do this kind of mistakes so did I. In subscription, the client can retrieve only those fields which are outputted in the mutation query. For example, if your mutation query looks like this:
mutation newMessage {
addMessage(input:{
field_1: "",
field_2: "",
field_n: "",
}){
field_1,
field_2
}
}
In the above mutation since we are outputting only field_1 & field_2. A client can retrieve the only subset of these fields.
So if in the schema, for a subscription if you have defined field_3 as required(!), and since you are not outputting field_3 in the above mutation, this will throw the error saying Cannot return null for non-nullable type: field_3.
Looks like the path [getMessages, sendBy] is resolving to a null value, and your schema definition (sendBy: Person!) says sendBy field cannot resolve to null. Please check if a resolver is attached to the field sendBy in type Messages.
If there is a resolver attached, please enable CloudWatch logs for this API (This can be done on the Settings page in Console, select ALL option). You should be able to check what the resolved Request/Response mapping was for the path [getMessages, 0, sendBy].
I encountered a similar issue while working on my setup with CloudFormation. In my particular situation I didn't configure the Projection correctly for the Global Secondary Indexes. Since the attributes weren't projected into the index, I was getting an ID in the response but null for all other values. Updating the ProjectionType to 'ALL' resolved my issue. Not to say that is the "correct" setting but for my particular implementation it was needed.
More on Global Secondary Index Projection for CloudFormation can be found here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-projectionobject.html
Attributes that are copied (projected) from the source table into the index. These attributes are additions to the primary key attributes and index key attributes, which are automatically projected.
I had a similar issue.
What happened to me was a problem with an update resolver. I was updating a field that was used as GSI (Global Secondary Index). But I was not updating the GSI, so when query by GSI the index exists but the key for that attribute had changed.
If you are using Dynamo DB, you can start debugging there. You can check the item and see if you have any reference to the primary key or the indexes.
I had a similar issue.
for me the problem was lying with the return type of the schema . As i was doing a query with PK on dynamodb table ..it was returning a list of items or data you can say . but in my schema i had a schema define as a singular struct format .
Error was resolved when i just made the return type in schema as list of items .
like
type mySchema {
[ID]
}
instead of
type mySchema
{
id : ID!
name : String!
details : String!
}
This error is thrown for multiple reasons . so your reason could be else but still i just posted one of the scenarios.

Weird Like Execution in grails

Am I missing something that I can't get the desired results ?.
For instance: I have 3 products with barcode 12345, 345678,888 and I enter 345...
If I use this:
I cant get 2 of the three records... What I am loosing that I cant pull them from the DB ?.
The like(String propertyName, String value) method accepts a domain class property name as its first argument. You cannot pass it a SQL expression like you're doing. For example: like('barcode', "%${barCode}%")
However, you can create a derived property in your domain class, use it to execute the SQL expression, and then use it in a criteria query.
class Product {
...
String formattedBarcode
static mapping = {
formattedBarcode formula: "to_char(barcode, 'FM BLAH BLAH BLAH')"
}
}
You can then use the formattedBarcode like this:
criteria.list {
like('formattedBarcode', "%${barcode}%")
}

Paging in Rediis

I am running local rediis for my application. I am using ServiceStack.Rediis client with C#.
I am storing items as an object type T with some key.
For example
Key "1234" : {
object {
name : "abcd",
value : "1"
}
}
I am storing something like 10000 objects of same type with key. I would like to apply pagination when i retrieve these objects and only show like 20 per page.
Is this possible? If yes, what should be a good way to resolve this?
Thanks,
Vivek
Use the SCAN command with a count of 20.

NHibernate filter criteria - Hour of DateTime

I am having hard times convincing NHibernate (EF was able to do it) to filter based on the Hour property of a DateTime entity property. My entity goes something like :
public class Invoice {
// ...
public DateTime Time { get; set; }
// ...
}
I need to retrieve all the invoices that were "made" at a certain hour (let's say 22). A possible query could be :
from i in s.Linq<Invoice>()
where i.Type.Id == Invoice.Type.Local &&
i.TimeOfRegister.Hour == 22
select i
However I am being thrown an exception stating that the property Hour of TimeOfRegister could not be resolved...
LE : The details of the exception : could not resolve property: TimeOfRegister.Hour of: MyCompany.Entities.Invoice
Sounds like NHibernate does not see the a DateTime as a component which has properties it can select on, it sees it as a single property. You probably have to use a function to obtain the Hour part of the DateTime.
In HQL for SqlServer2005: hour(i.TimeOfRegister)
Well I was advised by a colleague to take another route :
Define an int (or a byte) property on the entity (let's say "HourOfRegister") and then in the mapping class map it to a formula :
Map(a => a.HourOfRegister).Formula("DATEPART(HOUR, TimeOfRegister)");
Then I can use it in the query as I like it.