How to get original object after modifying with dojo.clone? - dojo

I have a object which returns from service say, studentInfo (which has id 1).
I have cloned as below:
this.studentsInformation=dojo.clone(studentInfo);
Now I try to update the cloned object - studentInfo
I have updated (say for id 1) and stored in database. If I create a new student info and try to update in a db, it has to go with id 2. But the object has id 1...
And also if I print this.studentsInformation, it is not showing the original object.. it has got modified object only..
So I want the original object after modifying and also I want to store the updated information after cloning as well. How can I achieve this?

why dont you store a reference in the clone to the original object ?
this.studentsInformation=dojo.clone(studentInfo);
this.studentsInformation.myMama=studentInfo;
Lucian

Related

questions on ObjectBox data model rename

Say I want to rename property "user" to "customer". I understand that I can add #Uid of "user" at the new property name. Like:
#Uid(123985252953064306)
String customer;
So I presume during the next build and run of my app, "user" in the database is renamed to "customer". My first questions are: can I then remove #Uid(123985252953064306) from my code for further builds? I guess the answer is yes if the app is only used by myself? So to maintain compatibility for endusers of the app, I still need to keep the #Uid annotation in the code. Is it correct?
My next question is: what if later I want to rename "customer" to "client"? Should I add an additional #Uid at the new property? Like:
#Uid(123985252953064306)
#Uid(124568645726267383)
String client;
The questions you are asking are covered by the docs in Data Model Updates and with some more background in Meta Model, IDs, and UIDs.
In short, once you put an #Uid on an property (or an entity) you can rename it anyway you want as often you want. ObjectBox takes the UID to identify the property and knows it been there before. Thus you need to keep it on the property.
So from
#Uid(123985252953064306)
String customer;
you can go to
#Uid(123985252953064306)
String someFancyName;
and back to
#Uid(123985252953064306)
String customer;
with keeping the same data for the property in the database.

when did C3P0 C3P0PooledConnectionPoolManager put second authsToPools's value?

when I read C3p0's code ,I discovered C3P0PooledConnectionPoolManager class has a filed called authToPools that store user'info and ConnectionPool map.It seemds that multiple datasource will create two datasoure which have its C3P0PooledConnectionPoolManager respectively. I wanna know when C3P0PooledConnectionPoolManager put the second map value. Thanks for your resoultion!

Entity Framework 5 foreign key values not updating (VB.NET)

I realise many similar questions have been asked but after attempting tens of examples I still cannot get this to work. The problem I am having involves the updating of foreign key values in the Users table.
I am creating a website using ASP WebForms, .net 4.5, Entity Framework 5, SQL server 2012.
I created the EF using database first, here you can see a sample of the model:
I am using a 3 tier architecture - my data access layer queries the database using LINQ and returns a User object (as defined by T4).
This means the object is disconnected from the context when it is modified. (right?)
I modify the object in the page's code behind, updating the UserRole by doing this:
(in page load)
Dim _userAcces As UserLayer = UserLayer.getInstance
mUser = _userAcces.getUserWithCustomerAndRole(_ID)
Dim _rolesAccess As UserRolesLayer = UserRolesLayer.getInstance
mRoles = _rolesAccess.listUserRoles
(on button click)
mUser.UserRole = mRoles.Item(dropDownRole.SelectedIndex)
At this point the mUser object holds the correct (updated) UserRole object. I then pass the mUser object back into my data layer to update the database. The simnplest examples I have seen do this:
Using _context As New SaasPortalContext
_context.Entry(updatedUser).State = EntityState.Modified
_context.SaveChanges()
End Using
I have also tried using:
_context.users.attach
getting the original from the context using _context.users.find(id) and updating the original from the updated User object
getting the dbentityentry object from _context.entry(updatedUser) and setting the property("UserRole").isModified property to true
Using any of these methods I expect the foreign key value for UserRole in the Users table to update to be the ID of a different role in the UserRole table, reflecting the changes in the mUser object, but this does not happen and the value does not change.
What am I doing wrong? Why will the ID not update in the Users table?
Any help would be greatly appreciated
I finally worked out what I was doing wrong, I did not check the box for "include foreign key relationships" when setting up the model, meaning the relationships were not properly defined (I assume).

Use Instance method instead of Database field while accessing in Rails

I have database field called name. And i have used user.name in my application. Now I have something like salutation which i wanted to append with the name. So what i basically want is when i am accessing name via user.name it should fetch the value from instance method rather then database field.
def name_with_salutation
"#{salutation} #{name}"
end
So when i am accessing name via user.name it should respond with user.name_with_salutation. I have tried alias_method but it shows stack level too deep because name is getting used in name_with_salutation so it got stuck in infinite process.
I am trying this because i do not want to replace name with name_with_salutation throughout the application. This should not apply when i am assigning values user.name = "abc".
Please let me know, How this will be done.
To overwrite an original Model method, you can write a method with same name, and then use read_attribute(:attr) to represent the original attribute value.
Given name attribute exist, to overwrite #name:
def name
"#{salutation} #{read_attribute(:name)}"
end

SPListItem id from SPField object

I am working on create a custom field type and for implementation issue I need to retrieve the ID of the SPListItem in the SPField class which belong to these field type but I can't retrieve it.
For example:
public class myField:SPFieldText
{
// I need ListItemID in this class
}
Can anyone help me please?
SPFieldText is an SPField, which is the schema definition for a field. Its like saying, given an SQL create table statement, give me the id of row x. Can't be done.
I think the logic you are trying to perform should be done in an event receiver, so say when an item is saved, you take the ID and add it to the text field.
I didn't find a solution but I've tried another solution which is
I can get the ID of the item in the New and Edit forms so I saved the ID and the field value as a one value separated by '/' and in the SPFieldText class I've been able to retrieve the ID value from the value of the field