setObjectId is not working - parse-platform

I wonder if is possible to assign an id when an item is created with parse:
ParseObject parseWord = new ParseObject(DataBaseHelper.TABLE_WORD);
parseWord.setObjectId(idRow);
parseWord.put(Word.NAME, word.getName());
parseWord.put(Word.TYPE, word.getType());
parseWord.put(Word.TRANSLATE, word.getTranslate());
parseWord.put(Word.EXAMPLE, word.getExample());
parseWord.put(Word.NOTE, word.getNote());
parseWord.put(Word.SYNC_AT, today);
parseWord.saveInBackground();
This code is not working, it doesnt save the item in the server. If I delete the setObjectId(idRow); it works. What am I doing wrong?.
Is there anyway to know when the saveInBackground is done?
Thanks

According to the ParseObject.setObjectID() API doc:
Setter for the object id. In general you do not need to use this.
However, in some cases this can be convenient. For example, if you are
serializing a ParseObject yourself and wish to recreate it, you can
use this to recreate the ParseObject exactly.
Also from the API doc:
An object id is assigned as soon as an object is saved to the server.
A reason, as the quote suggests, you might need to set the object ID is if you, wish to do something like save the fields of a parse object to a file. If you wanted to take the fields from your file and recreate a parse object, THEN you'd need to set it, as that's not done for you if you're not saving it to the server and just using an instance of the object for purposes internal to your application.

Related

Obtaining / iterating through data in the laravel service container via app()

If I do dd(app()) within my app I can see data that is useful to me within the #resolved branch of the service container object that is returned to screen.
A really silly question though; what is the easiest way of iterating through that data ? I've tried things like app()->resolved which don't work.
Well $resolved array is protected for something, however you can use reflection to get it:
$rp = new \ReflectionProperty('\Illuminate\Foundation\Application', 'resolved');
$rp->setAccessible(true);
dd($rp->getValue(app()));

macOS command line app - User Defaults dictionaryRepresentation shows too many values

I a developing a macOS commandline application in Xcode, which uses User Defaults. I have the following code for my User Defaults
if let configDefaults = UserDefaults.init(suiteName: "com.tests.configuration") {
configDefaults.set("myStringValue", forKey: "stringKey")
configDefaults.synchronize()
print(configDefaults.dictionaryRepresentation())
}
This will create my own .plist file in the ~/Library/Preferences folder. If I look into the file, I can see only my single value which I added, which is perfectly fine. But when I call dictionaryRepresentation() on my UserDefaults object, the there are a lot of other attributes (I guess from the shared UserDefaults object), like
com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture or AKLastEmailListRequestDateKey
Looking into the documentation of UserDefaults, it seems that this has to do with the search list of UserDefaults and that the standard object is in the search list:
func dictionaryRepresentation() -> [String : Any]
Returns a dictionary that contains a union of all key-value pairs in the domains in the search list.
There are also the methods addSuite and removeSuite for a UserDefaults object, so I am guessing I need to remove the .standard suite from my configDefaults object, but I don't know the name, which should be used for that in the method.
Is it possible to remove the .standard defaults from the dictionary representation? I basically just want all of my own data in a dictionary, nothing more.
The reason I am trying to get only my values from the UserDefaults, is that a have a number of object of a custom type Connection (which store the configuration to connect to a server), which are saved in the UserDefaults. On program start I want to be able to load all objects into my app. Therefore I thought I could use dictionaryRepresentation(), as it would return all elements in the UserDefaults. But then there should be only my Connection objects in the dictionary, so that I can cast it to [String: Connection].
Given your purpose (in your latest edit of your question), what you should do is store a collection of Connection objects under a single key. Then, look up that key to get the collection.
It's not clear if the collection should be an array of Connection objects or a dictionary mapping strings to Connections. That's a choice you can make.
But, in any case, you shouldn't rely on the defaults being empty of everything else.
In other words, you would do:
UserDefaults.standard.set(yourStringToConnectionDictionary, forKey:"yourSingleKey")
and later:
let connectionMap = UserDefaults.dictionary(forKey:"yourSingleKey")
then look up Connections in the connectionMap by their name/ID/whatever.
Though the other solution proposed by Ken Thomases may be better from a design standpoint, I've found a solution that does exactly what I initially wanted. Calling
UserDefaults.standard.persistentDomain(forName: "com.company.TestApp.configuration")
Returns a dictionary containing only the values I've added to the domain com.company.TestApp.configuration, using
let configs = UserDefaults.init(suiteName: "com.company.TestApp.configuration")!
configs.set(someData, forKey: someKey)
Strangely in the Apple documentation says this about persistentDomain(forName:):
Calling this method is equivalent to initializing a user defaults object with init(suiteName:) passing domainName and calling the dictionaryRepresentation() method on it.
But this is not the case (see my question). Clarification on that subject is more than welcome.

How does one read the data value from a Function outside FunctionCallbackInfo?

When I create a function like this:
v8::Function::New(<Isolate>, <C_Function>, <Data_Value>);
The Data_Value that I supply is useful for many things and I can access that when the function is called, with something like FunctionCallbackInfo->GetData().
But I have found no way to get back this data in a different scenario. Let's say I store that Function in a Persistent object, and then I would like to read which data is currently bound to it. Any ideas?
I don't think it's exposed via the API.
But there's an alternative:
manually construct a v8::FunctionTemplate
set its ->InstanceTemplate()->SetInternalFieldCount(num_fields)
get the v8::Function from the template with template->GetFunction(context),
now you should have function->InternalFieldCount() == num_fields
you can use function->SetInternalField(index, value) and function->GetInternalField(index) to store any data you want.
For complete examples, search for "SetInternalFieldCount" in V8's test-api.cc.

How to create an empty activerecord object in rails 4?

I am trying to develop a Rails application for QuickBase for which there is no adapter. I checked online for the QuickBase adapter but it is not working as it is for a very old version of rails and the author told me that he no longer supports it.
I want to be able to use the Active Record and the associated concepts of a typical rails application, but intervene and modify how the create, update and show actions work. I have created the application to create a new record successfully. However, when I want to be able to edit the record, I have first modified the edit action to go to my own database and get the data into an active record object.
To create an empty Active Record I said $user = User.new
Then I populated all the attributes with the data from my custom database. But the form still shows the Create User button, instead of Update User button. Apparently, I guess this is because the persist? method is returning false as this is a "new" object. But I know this is not a new one. So how do I influence the #user object to think it is a persistent one?
Alternatively, is there a way I can create the blank #user object without the new function?
I have checked all over the place, but couldn't find any clue on how to accomplish this. Thank you so much for your help.
You can try calling #user.disconnect! after your call #user = User.new, which will keep ActiveRecord from trying to write to the database, but I'm not sure that will solve your problem.
The larger problem is that you're trying to fit a square peg into a round hole here. The entire point of ActiveRecord is to abstract the connection to a database. So without a database, what's the point?
I think your best solution would be to write your own QB adapter. It may not be as difficult as you think, since you already seem to know how to read/write to the database.
You can read more about how to do that here: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/AbstractAdapter.html

breeze: custom enum values

Enums come back from the server as myEnum.SomeValue but what I'd like to show on screen is a formatted value such as "some value" instead of SomeValue.
That could be part of an attribute on the server-side model but it won't be passed in the metadata.
What's the best place then to do that kind of thing with breeze ?
We've discussed the idea of "extensible" metadata for Breeze but have not yet implemented it. Please vote for this here.
But in the meantime, there is nothing stopping you from "enhancing" the metadata returned by Breeze yourself. The best way to do this would be to add your own properties to either the "MetadataStore", "EntityType" or "DataProperty" classes.
The advantage of adding your custom metadata to existing metadata objects is that this data will be available whenever you work with any of the basic Breeze metadata.
Perhaps something like this: ( I haven't actually confirmed that this code is correct)
var custType = myEntityManager.metadataStore.getEntityType("Customer");
// assume that the 'status' property is actually an enumerated value where you want to
// add some custom metadata.
var statusProp = custType.getProperty("status");
// enumDescriptions is your custom property
statusProp.enumDescriptions = {
"PaidUp": "Paid Up",
"Delinq": "Delinquent",
"InArr": "In Arrears"
};
Now anywhere that you get given the "status" dataProperty, ( such as in a Validation), you will also have access to your "enumDescriptions"
Hope this makes sense.

Resources