Does removing all data from a Sencha store also remove associated data? - extjs

I have a store and a model with a hasMany association.
If I call Ext.getStore('SessionStore').removeAll() does it also remove any associated data with the records in the store?
If not, how would I do this?

if you console log a record in SessionStore you should have a property with the name of the association plus the suffix Store
e.g. if the name of the association is personalInformation there should be a new property in the record called personalInformationStore.
So the answer would be yes by removing a record or all from a store the associated data will also be removed as this data is part of the parent object.
Perhaps Ext.StoreManager.getCount() can help validate the existence of the data / objects.
I also recommend this chrome extension: https://chrome.google.com/webstore/detail/app-inspector-for-sencha/pbeapidedgdpniokbedbfbaacglkceae?hl=en

Related

How to bind uploaded file with ADAM to entity field correctly in 2sxc module?

I need to create entity object programmatically and fill it with data. One field needs to be of a file type. So I managed to create entity without file, upload file in ADAM using this sample of code. However it seems that I didn't bind it as it is binded when file is uploaded manually.
When a file is uploaded to entity field manually, you can see content like file:421 .../asdf.docx. However when I repeat code sample from link above, field contains that file available to choose and already uploaded, but field value is null. IFile.Url seems to write correct data via App.Data.Update method, but no id is displayed in admin panel.
Dictionary<string, object> fileDict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) {
{ "File", file.Url }
}; // file is ToSic.Sxc.Adam.IFile, returned by SaveInAdam
App.Data.Update(entityObj.EntityId, fileDict); // entityObj is ToSic.Eav.Data.IEntity, returned by App.Data.Create
I wonder if that's going to have some bad conscequences if it has no binding like manual upload and how to do that correctly?
To add files, you actually add them to a field (so that the UI can then offer them as if they were added by a normal user). Check out https://docs.2sxc.org/api/dot-net/ToSic.Sxc.Dnn.Web.IDynamicWebApi.html#ToSic_Sxc_Dnn_Web_IDynamicWebApi_SaveInAdam_System_String_System_IO_Stream_System_String_System_String_System_Nullable_System_Guid__System_String_System_String_
BTW: Best check out MobiusForms to see how it's done.
And I forgot to mention: here the docs https://docs.2sxc.org/web-api/custom-web-api-dotnet-saveinadam.html
To further explain:
SaveInAdam will place the file in the ADAM folder of the item. Since it could be that many files are added, it's just assuming that the field will be the library type - which doesn't store anything in the entity, it just automatically finds the folder that belongs to the field.
If you wish to not use the library feature but actually just the single-field with link, then you must also save the term like "file:74" into the value of the field.

extjs store.getById() fails

I'm trying to get an Associated Model (E.g. groups and associated users) from a store with:
Ext.each(this.getView().getSelection()[0].getAssociatedData().users,function(element){
var theuser = myStore.getById(element.id);
theuser.set('deactivated','true');
}
This works for the first 25 Users (id 1-25) however the store is filtered through a pagination plugin. In reason of the filtering with offset and limit the requested id isn't in the local store.
any idea on how to force the store to get the model from remote in case the id isn't available in the local cache?
Or is it anyhow possible to use the data from getAssociatedData, change something and write the record back through the writer proxy?
thx, I really appreciate your help!
The store's getById() method will only return the locally-available records.
If you want to retrieve a model, and you know the id already, you can simply do <model class>.load(id). (If the model is unknown, you can do myStore.getModel().load(id)
Note that the load method returns immediately, but it returns a stub - you'll want to use a callback to process the change to the deactivated field.
In ExtJS5, the Session support will help ensure that the models referred to in both the association store and your myStore object refer to the same model instance.

show unedited version of model data

I have an Entry model as follows:
class Entry(models.Model):
date_posted = models.DateTimeField(auto_now_add=True)
last_edited = models.DateTimeField(auto_now=True)
author = models.ForeignKey(CustomUser)
title = models.CharField(max_length=150)
description = models.TextField()
tags = models.ManyToManyField(tags)
Now, whenever a user creates or edits an Entry object we send it to the moderation queue and the object is not available to the default manager for Entry object until it has been moderated. It makes sense when a user is initially creating an object but when a user is edit the entry object it disappears from the search results. We also offer users to save or bookmark, different entries. so the edited Entry object is not available in the saved entries anymore until it has been moderated.
What I am looking to do is to have the old Entry show up until the edited Entry is under moderation once the edited entry object is moderated we can replace the edited entry with the original one.
One way I can think of is to create a different Entry Object for each edit a user makes but I am not quite sure if that is a feasible and a sensible approach to handle this situation wouldn't it just have a lot of duplicate data in the database ??
Questions:
what are my options ? (I would also like to know which ones would be the best performance-wise)
Is there a way I can achieve this without duplicating the object ?
In my opinion, if the number of objects that are sent to the moderation queue is low to moderate, you can have a ManyToMany (Infact a One to Many is what you want) field which keeps references to the versions from the Entry object.
If this is not feasible, you can look into django-pickle-field which lets you store any object types into the database. So, you can create an additional nullable column, in which you would save the form data on edit as-is and make it available in the moderation queue.
So, the logic for moderation queue is something like:
MyObject.objects.filter(pickle_field__isnull=False)
Once the moderator approves, override the field data into the object.
else, discard the picklefield.
If you want to allow multiple edits, or keep track of moderation history, you can make that a ManyToMany with more info (such as edited by, moderated by, etc.) in the intermediary table.

How to identify a BackboneJS Model serverside

I'm just getting my head around BackboneJS, but one of the (many) things I'm still struggling with is how exactly the Models Sync up and relate to the serverside DB records.
For example, I have a Model "Dvd", now I change an attribute on the "Dvd" Model, the Name for example, and then I call save(), how exactly does the server side know what DB record to update? Does Backbone hold the DB row ID or something else?
Yes, typically you will set up your Backbone models so that they have database row IDs for any objects you're working with. When one of them is brand new on the client side and not yet saved to the server, it will either have a default or no ID, which doesn't matter since the server will be assigning the ID if and when the initial save transaction succeeds.
Upon saving or updating a model item, Backbone expects the server to reply with some JSON that includes any attributes that have changed since the save or update request was made. In the response to the initial save request, the server informs the client of a newly saved item's row ID (and you can also send along any other information you might need to pass to the client at the same time).
By default, the 'id' attribute of a model object is assumed to be its unique identifier, but backbone lets you change this if you're using a different identifier for the primary key. Just give your model an idAttribute parameter (see the docs for Backbone.Model.extend()) to do that.
Meanwhile, either the urlRoot parameter or a url function can be given to your models to characterize the urls that should be used to send the various ajax requests to the server for a given model.

Populating a field in wpf

I have a database of finance info and i want to check that supplied totals 'add up'. I have added fields to the database for the check data and am using data binding via the Entity Framework. How do i populate these 'check' fields while the user is adding data to the record?
Eg The form contains SubtotalA, SubtotalB and TotalAB textboxes. The database has these fields plus CheckTotalAB. The user keys in SubtotalA, SubtotalB and TotalAB from a hard copy form. I want to populate CheckTotalAB with the sum of SubtotalA and SubtotalB to compare against the provided TotalAB.
I first tried getting the data from the textboxes. Unfortunately txtSubtotalA.Value doesn't exist.
I then thought I'd have to go to the entity itself. Unfortunately I don't know how to access the current record/entity being entered and if I did, how would I access the value of fields that haven't been saved yet.
Can someone point me in the right direction?
tia
mcalex
Accessing the entity was the answer. This was accomplished through use of an entity property in the datacontext that i set to equal a class member i added to my form class.
After that getting to the entity's fields including my calculated fields was just a case of getting/setting the member's properties.

Resources