Get generated store Id in Ext.Net - ext.net

I have a Grid panel generated for the property model:
X.GridPanelFor(m => m.InvoiceItems, false, true, false)
True means that the Store is generated for this grid.
I cannot add a Store ID property for this grid because I get an error
X.GridPanelFor(m => m.InvoiceItems, false, true, false)
.StoreID("StoreName")
Error:
Please do not set both the StoreID property on
GridPanelCust and inner property at the same time.
I have tried pulling out the store ID from code like this:
App.GridPanelCust.getStore().getId()
But the error reported is that the
getId() is not a function
Anyone know how can I pull out the Store ID from GridPanelFor generated one?

Related

How to customize link properties when creating ArangoSearchView in ArangoJS

I try to create an ArangoSearchView in arangojs, but I don't know how to set up view properties.
Here is my code:
const link = {
includeAllFields: true,
fields: { val: { analyzers: ["text_en"] } },
storeValues: "val"
};
const view = _db.view(`${_viewName}`);
await view.create({ links: {mergeDB : link } });
However, I got this result:
As the error says the issue it's with the storeValue field
According the docs the value should be either none (default) or id
storeValues (optional; type: string; default: "none")
This property controls how the view should keep track of the attribute values. Valid values are:
none: Do not store value meta data in the View.
id: Store information about value presence to allow use of the EXISTS() function.
Not to be confused with storedValues, which stores attribute values in the View index.
Note that there is other parameter called storedValues but it's a top level field (same level as links)

Use Bookshelf patch to set default values for unreferenced columns

Here's my goal: Check if an entry exists in the postgres database. If the entry exists, update some of the columns in the entry with data I provide while setting unreferenced column values to null (or the default value). Otherwise just save a new entry.
I've been trying to understand what the patch argument actually does in bookshelf. It seems I can pass it with true or false and nothing changes in the behavior. From what I understand though it seems that passing it a false value should update all columns.
Let's say I have a table called table with columns user_id, timestamp, property1, property2. What I want to achieve with the below code should update the entry with the supplied values, but set property2 to the default value.
Models.table
.where({user_id: session.userId})
.fetch()
.then(tableEntry => {
let newTableEntry = {
user_id: session.userId,
timestamp: new Date(),
property1: "a string"
}
if (tableEntry){
return tableEntry.save(newTableEntry, {patch: false})
}
else {
return new Models.table().save(newTableEntry)
}
})
The only way I can seem to do this is explicitly set the other columns to null.
Why the patch option seems to make no difference
The reason you're not seeing any difference when using either true or false in the patch option is because you're already passing most of the attributes to update in the save call (user_id, timestamp and property1), and I assume that property2 already has a default value set in the database. So, patch will only update those 3 columns but since you're not passing the fourth one it will remain with its current value. If you don't use the patch option then the update query will use the value of property2 already set on the model which is the same as what's already on the database, therefore the patch option is almost useless in this case.
Patch's main difference is in the generated queries that are more efficient.
Updating an attribute with NULL
Now, if you explicitly pass an attribute value as null in the update statement it will set it to NULL in the database, but if you don't include that attribute then it won't be set:
tableEntry.save({timestamp: new Date(), property1: null}, {patch: true})
// UPDATE my_table SET timestamp = '2018...', property1 = NULL WHERE user_id = 1
tableEntry.save({timestamp: new Date()}, {patch: true})
// UPDATE my_table SET timestamp = '2018...' WHERE user_id = 1
Updating an attribute with a DEFAULT value
There's currently no support for that feature on Bookshelf. You can open a new feature request for that if you want.
However there's a similar feature that will allow you to use some default values in an update statement but you will have to provide these values yourself, without relying on the database to do it for you:
tableEntry.save({timestamp: new Date()}, {patch: true, defaults: true})
This requires that the model has an attribute with the default values:
var MyModel = bookshelf.Model.extend({
defaults: {property1: 'foo', property2: 'bar'},
tableName: 'my_table'
})
This feature isn't properly documented unfortunately, but it should work as intended.
When to use patch
This method is usually used when you fetch a model from the database like you did, but you're only interested in updating some of the attributes of the model. This is useful because by default Bookshelf will generate a query that will try to update all the attributes that are set on a model, not only those that are passed to save:
Models.table.forge({user_id: 1}).fetch().then(tableEntry => {
// tableEntry has all attributes set with a value
return tableEntry.save()
// This will generate a query like:
// UPDATE my_table SET user_id = 1, timestamp = '2018...',
// property1 = 'foo', property2 = 'bar', WHERE user_id = 1;
})
Using patch:
Models.table.forge({user_id: 1}).fetch().then(tableEntry => {
// tableEntry has all attributes set with a value
return tableEntry.save({property2: 'something'}, {patch: true})
// This will generate a query like:
// UPDATE my_table SET property2 = 'something', WHERE user_id = 1;
})

How to autogenerate id if there is no id in document with elasticjs v5.0

I am trying to add documents, according to elastic search documents, we can add document, even if we dont provide id... See Here
I am trying to add a document even if it doesnt have any ID. in elastic search, how can i do that?
My current code looks like this
var params = _.defaults({}, {
index: index,
type: type, //'customer'
id: data.id || null,
body: data
})
debug(params)
return this.client.create(params);
The above code gives this error
{
"error": "Unable to build a path with those params. Supply at least index, type, id"
}
Any hint would help, thanks
With the create call you MUST provide an id.
If you are not sure if an ID will be present in your data , then you can use the client.index() function instead. using that function, ES will auto-generate an ID if none is provided.

Can't delete an object in IndexedDB with auto_increment key

I can really use some help on my code.
I'm using IndexedDB in my web app, and I've created two objectStore :
- companyToCall
- companyCalled
Both contain Company objects (custom class in js I've made).
Here goes the schema :
databaseOpeningRequest.onupgradeneeded = function(event)
{
db = event.target.result;
db.createObjectStore('companyToCall', { autoIncrement: true }).createIndex("id", "id", { unique: true});
db.createObjectStore('companyCalled', { autoIncrement: true }).createIndex("id", "id", { unique: true});
}
I've decided to not use Company.id as a key in the DB because I wanted to memorize the order of insertion in database, for instance you insert subsequently companies with id 25 20 and 30 in the db, I want their keys to be like this : company 25 -> 1 / company 20 -> 2 / company 30 -> 3
All those companies are first inserted in the CompanyToCall Storage and when I'm done working with one I want to put it in the CompanyCalled storage and delete it from the CompanyToCall Storage.
Unfortunately, the deletion in the CompanyToCall storage won't work and I can't figure out why.
Here is the deletion :
var removeCompanyFromToCallStorage = function(company)
{
if (activateLocalStorage)
{
var requete = db.transaction(['companyToCall'], 'readwrite').objectStore('companyToCall').delete(company.getId());
requete.onsuccess = function(e)
{
console.log('worked');
};
}
};
I got the "worked" on my console but when I'm checking my db I can still see this company in the wrong storage (after refreshing etc etc)
Does anyone have any idea?
First, you need to specify a keypath when creating your object stores in order to reference objects by an id. A keypath is like the primary key of a record in an ordinary relational table. Using a keypath is optional. You currently have no primary key defined, so doing a delete-by-primary-key operation, without specifying which field in the object represents the primary key, does not make sense. You can define a keypath by changing db.createObjectStore('companyToCall', { autoIncrement: true })... to db.createObjectStore('companyToCall', {keyPath: 'id', autoIncrement: true}).... See IDBDatabase.createObjectStore for additional information.
Second, IDBObjectStore.prototype.delete fires a success event regardless of whether an object within the object store was modified. Many operations in indexedDB fire success events regardless of what actually happened. Basically success just means that you properly requested the operation to be performed and that the operation completed. It does not mean the operation did something. This is why 'worked' is always displayed in your console. Unfortunately, there is no simple way to detect whether the object was actually deleted. Instead of 'worked', you can only print something like 'successfully requested object to be deleted', but you will never know if the request actually did anything unless you create a later get request to check it.

HasMany with JunctionTable findAllJoin not serializing junction table attributes

So I have a User model which is connected to projects via a junction table. This junction table has some additional attributes like allow_read which I want to pass back in my response.
request.user.getProjects({
where : { do_sync : true, allow_read : true },
}).success(function(projects) {
// send proper response
response.jsonp(projects);
}).error(function(err) {
// send error response
response.status(500).jsonp(err);
});
In this code block 'allow_read' works properly and projects[0].user_project returns the additional attributes from the User_Project model. The problem is when 'projects' get serialized the user_project object disappears. projects[0].values also does not contain a user_project property even though projects[0].user_project does exist.
My question is if there is anyway for sequelize to automatically stringify both the projects and their junction table attributes without manually building that object myself?

Resources