How to get two class objects from on PFQuery in ios sdk? - iphone

In my application i am using parse sdk. In parse sdk databrowser i have two classes.
ClassA and ClassB .
Both classes are independent. they dont have any relation. I want to write a single query which gets objects from both classes in one array.

The current version of Parse SDK (1.2.12) does not provide such feature right out of the box.
The PFQuery Class only provides methods such as queryWithClassName: limited to one Class at a time.
You have to create and execute two separate PFQuery.

DBar is right. You can not download two different classes with the same query.
My solution was to make one universal class with a "type" field that I could use to parse out which class it should belong to on the user end. That way I could combine the two queries and sort out which belongs to which class on the user end.

You can have a Join Table
Class C which includes both Class A and Class B
so with just one query you can fetch both Class A and Class B
using includeKey.
PFQuery *query = [PFQuery queryWithClassName:#"ClassC"];
[query includeKey:#"classAObject"];
[query includeKey:#"classBObject"];
NSArray * results = [query find];

Related

linQ to entities does not recognize the method Models.Repository.Student get_Item(Int32)' method

getting this error on where clause.
trying to fetch records from sql server with linQ query in entity framework.
var Stud = contextSchool.Student.Where(x => x.STDNT_ID == lstStudent[i].StudentID).FirstOrDefault();
if i store value of list in a variable and then use in where clause, it works but not with list.
complete error:
linQ to entities does not recognize the method Models.Repository.Student get_Item(Int32)' method, and this method cannot be translated into a store expression.
i also get this error on some other projects, the problem is that u cant use methods like get_Item or f.e. AddDays() in ur linq command.
So u kinda have to play around it.
U have to create an object (list, or whatever) before ur linq command and fill it with the data u need (per methods) and use the variable in ur linq command.

OrientDB: Filter select on super class

Using the OrientDB console there is a command to show all records with a class that extends a base class.
browse class Asset
This returns all records that have a class (Object1, Object2) that extends Asset.
I'm looking for a SQL command that can do the same.
Currently this query does not return the same set of records.
SELECT * V where #class = 'Asset'
you can also use instanceof operator,
eg.
select from V where #this instanceof 'Asset'
This makes sense especially in v. 2.1 where you have multiple inheritance, in cases when you want to retrieve documents that are subclasses of two different parent classes
To retrieve all the records from Object1 and Object2, a simple select query from the superclass name should work :
select from Asset
If you are looking for all superclasses of a given class, this worked for me:
select superClasses from (select expand(classes) from metadata:schema) where name = "myClassName"

Spring data find by "_class " value

We are using spring data mongo repositories to store/retrieve documents. Following is the Java structure of classes we have got:
Abstract class A -> Concrete Classes B and C
We are writing the documents using save() method. when a document is saved, "_class" variable is saved which stores the classPath.
Now, when we try and query the data, we are getting the documents of both B and C classes. Following is the example:
public List<B> findByName (String name);
When we call this method, the list (surprisingly) contains the objects of C as well. It may be because B and C have one property which has same name.
My question is, if we want to restrict the result to specific class, is it possible using Mongo repository?
We tried with findBy_Class, findByClass but it threw an exception saying it was not able to find "class" member in "B".
Shouldn't the return type (e.g. List<B>) help filtering the objects? Any ideas?
Thanks in advance.
On the query object there's a "restrict" method which returns only objects of a given type.
http://docs.spring.io/spring-data/mongodb/docs/current/api/index.html?org/springframework/data/mongodb/core/MongoOperations.html
I suppose you could do something like that :
query.restrict(B.class).findByName(...)

Attempting to use EF/Linq to Entities for dynamic querying and CRUD operations

(as advised re-posting this question here... originally posted in msdn forum)
I am striving to write a "generic" routine for some simple CRUD operations using EF/Linq to Entities. I'm working in ASP.NET (C# or VB).
I have looked at:
Getting a reference to a dynamically selected table with "GetObjectByKey" (But I don't want anything from cache. I want data from database. Seems like not what this function is intended for).
CRM Dynamic Entities (here you can pass a tablename string to query) looked like the approach I am looking for but I don't get the idea that this CRM effort is necessarily staying current (?) and/or has much assurance for the future??
I looked at various ways of drilling thru Namespaces/Objects to get to where I could pass a TableName parameter into the oft used query syntax var query = (from c in context.C_Contacts select c); (for example) where somehow I could swap out the "C_Contacts" TEntity depending on which table I want to work with. But not finding a way to do this ??
Slightly over-simplyfing, I just want to be able to pass a tablename parameter and in some cases some associated fieldnames and values (perhaps in a generic object?) to my routine and then let that routine dynamically plug into LINQ to Entity data context/model and do some standard "select all" operations for parameter table or do a delete to parameter table based on a generic record id. I'm trying to avoid calling the various different automatically generated L2E methods based on tablename etc...instead just trying to drill into the data context and ultimately the L2E query syntax for dynamically passed table/field names.
Has anyone found any successful/efficient approaches for doing this? Any ideas, links, examples?
The DbContext object has a generic Set() method. This will give you
from c in context.Set<Contact>() select c
Here's method when starting from a string:
public void Test()
{
dynamic entity = null;
Type type = Type.GetType("Contract");
entity = Activator.CreateInstance(type);
ProcessType(entity);
}
public void ProcessType<TEntity>(TEntity instance)
where TEntity : class
{
var result =
from item in this.Set<TEntity>()
select item;
//do stuff with the result
//passing back to the caller can get more complicated
//but passing it on will be fine ...
}

Editing Core Data row from entity linked to managedObjectContext via relationship

I need to edit a row of data in an Entity that has a relationship with my main Entity from my fetchedResultsController, in this case "theUser" being an instance of my User entity.
I basically need to edit one of the CannedMessage rows that already exist and save it. I can access the "Messages" fine as you see below, but am unsure once I have found the CannedMessage I want as to how I save it back into the managedObjectContext for "theUser"
Any advice?
NSArray *msgs = [theUser.Messages allObjects];
NSPredicate *activeMatch = [NSPredicate predicateWithFormat:#"defaultMessage == 1"];
NSArray *matched = [msgs filteredArrayUsingPredicate:activeMatch];
CannedMessage *msgToEdit;
for(CannedMessage *msg in matched) {
msgToEdit = msg;
}
Your trouble is that your thinking in SQL terms instead of Core Data's object oriented terms. The data you are looking for is not in an SQL row but in the attribute of a managed object. In this case (I assume) you are looking for an attribute of a CannedMessage instance.
The matched array will contain either managed objects initialized with the CannedMessage entity or an instance of a dedicated NSManagedObject subclass (if you setup one which it looks like you did.)
Lets say the attribute is named theMsg. To access the attribute in the generic managed objects:
for(CannedMessage *msg in matched) {
msgToEdit = [msg valueForKey:#"theMsg"];
}
... to access a custom class:
for(CannedMessage *msg in matched) {
msgToEdit = msg.theMsg;
}
It's really important when learning Core Data to simply forget everything you know about SQL. Nothing about SQL truly translates into Core Data. Core Data is not an object-oriented wrapped around SQL. Entities are not tables, relationships are not link tables or joins, attributes are not columns and values are not rows. Instead, Core Data creates objects just like you would if you manually wrote a custom class to model a real world object, event or condition. Core Data uses SQL almost as an after thought as one of its many persistence options.
In my experience, the more you know about SQL, the harder it is to shift gears to Core Data and other object graph APIs. You want to translate the new stuff to what you have already mastered. It is natural but resist the urge.