Parse schema add field if not existent - parse-platform

In our code we have an init function, which creates all the schemes, sets up the ACL...
How am I supposed to handle changes in the schemas(For example when adding a new field for an schema, or changing the CLP). My primitive approach was to just set all the attributes and call update. This throws an exception saying "Field name exists, cannot update".
My goal would be to just call update if there are changes it applies them otherwise, it just does nothing.
Any hint how to achieve this? Or is this in general the wrong approach?

Related

`r.row` and `r.contains ` in nested queries not working

Trying to add a new field inside of a document using a field from another table. I first tried to use r.row
r.db('client').table('basic_info').filter({name:'Andre Pastr'}).update({teacher_name: r.db('teacher').table('basic_info').contains(r.row('name').eq('Nicholas Derma')).pluck('id')});
and it returned the message:
e: Cannot use r.row in nested queries. Use functions instead in:
r.db("client").table("basic_info").filter({name: 'Andre Pastr'}).update({"teacher_name": r.db("teacher").table("basic_info").contains(r.row("name").eq("Nicholas Derma")).pluck("id")})
^^^^^
so then after finding this [vague entry][1] in the github issue log I just decided to just change the syntax of my query and run:
r.db('client').table('basic_info').filter({name:'Andre Albuquerque'}).update({teacher_name: r.db('teacher').table('basic_info').filter({name: 'Nicholas Chadwick'}).pluck('id')});
That returned the error message:
: Could not prove argument deterministic. Maybe you want to use the non_atomic flag?
Three inter-related questions: How might I use contains to run such a query? What am I doing wrong with this second query? Why doesn't r.row work in the first query?
You can't use r.row in the first query because it's ambiguous whether it should be bound to contains or to update. (We could define which one it's bound to, but it's very confusing for people because most people haven't memorized all the terms that could possibly bind r.row, so it's easier to force people to name their variables in ambiguous cases.)
You have to specify the non_atomic flag because the function you're passing to update can't be applied atomically (since it isn't deterministic). The way you wrote it, it will be executing a table fetch for every row in the original filter.
You probably want to write something like this instead:
r.table('basic_info').filter({name: 'Nicholas Derma'}).pluck('id').do(function(nderma) {
return r.table('basic_info').filter({name: 'Andre Pastr'}).update({teacher_name: nderma);
})
You should consider creating a secondary index on name and using getAll instead of filter if you run this query often.

Custom Symfony2 Validator Constraint Messages

I want to use custom error messages for validation constraints on dozens of fields in my project.
I do not want to set the message on every one of these, because that would be a blatant violation of DRY. Repeating the same string in every declaration like: #NotNull(message="custom msg") would mean that if I decide to change the message in the future I'd have to hunt them all down replace them, but even worse I might use the wrong string on some of them and be inconsistent.
How do you deal with this?
Is the best option really to extend every symfony stock constraint and set my default there, and use my own custom annotation class?
Please note that using the translator is not an option for me, so I am looking for a solution that does not include the symfony translation component.
Thanks a lot for the help in advance.
Assuming you are working with English as the app's language, and you've configured translator: { fallback: en }, you can override these constraint messages universally. Start by creating this file: app/Resources/translations/validators.en.yml
And use the following translation format:
This value should not be blank.: Your custom message here
Whatever the standard message is.: Another custom message
This also works for any other language setting, assuming you've made a validators.lang.yml for it!
You can also place this file in your bundle directory under Resources/translations, and a few other places.
You can read more about this here!

SharePoint Business Connectiviy Data Model Update method failing

I have an external list in SharePoint that references a BCDM I created inside visual studio. The entity as an ID that is auto generated in the database, which means it's read-only.
Create and read method works fine, I'm trying to implement the update method. I have set an input parameter that match my entity and I'm getting this error.
Failed to update a list item for this external list based on the Entity(External Content Type) ‘Notification’ in EntityNamespace ‘Namespace’. Details: The TypeDescriptor with name ‘Id’ in the Method ‘Microsoft.SharePoint.BusinessData.MetadataModel.Static.Method’ on Entity (External Content Type) with Name ‘Namespace’ in Namespace ‘Notification’ is marked ‘PreUpdaterField’, but is contained by another TypeDescriptor marked ‘PreUpdaterField’.
I tried every possible combinaison to make this work, make the id type descriptor read only, pre-updater field = true/ false/, updater field = true/false, removing it, adding another parameter outside the entity. NOTHING WORKS !!! Obviously, I'm about to commit a murder as something so simple just turned out to be the biggest waste of time in my programmation history. What can I do to make this works??
This has been resolved and is explained here:
http://www.dotnetmikael.com/2014/02/sharepoint-2013-bcdm-with-visual-studio.html

Differentiating between new documents and restored documents in a Cocoa application

In my project I need to be able to tell the difference between documents created by the user and those restored at application launch by restoreStateWithCoder because there are some thing s that need to be done for new documents, but not restored ones. How can I do this?
How about subclassing "NSDocument" and using that subclass for your document?
Then, you can catch "restoreStateWithCoder" as it happens and set a unique flag (e.g. a BOOL property) for those documents that are restored from disk and not created fresh via "File -> New" command.
You can also attempt to "method swizzle" "restoreStateWithCoder", but you have to decide what property to set in which object.
[Answering this for Swift, but the general idea works for Objective-C as well]
When a document is brand new, you generally get a call to the following function:
convenience init(type tyepName: String) throws
You could set a flag in that function (say needSpecialHandling = true, a variable which is originally initialised to false) to say whether you need some special handling for such cases.
Then in the makeWindowControllers() function you use that variable to trigger invoking the special code (if true) the same way you invoked it possibly in the windowControllerDidLoadNib function.

EnvDTE CodeClass.AddDelegate overload

I want to create 2 delegates with the same name but different parameters (overloaded delegate). When I try to add a delegate I get an error on the second try due to a delegate already existing. I tried to add it first with a temp name then add the parameters and then change the name so the signuature would be different but I still get an error stating that an item already exists with that name.
How can I add an overloaded delegate?
The capabilities of the code model to generate code are limited. You can try the to use EditPoint.Insert(...) to insert the code instead of using AddDelegate() method.

Resources