Core Data Relationship shown in tableView - core-data

I am developing an application with a tableview showing the content of a core data table.
The datamodel is something like this:
Entity(name, code)->>Translation(text, code)
I retrieve all the entities using the usual NSFetchedResultsController, but then once is time to populate each row (through tableview cellForRowAtIndexPath:) I have to dive into each entity to retrieve 2 translations based on the code inputed by the user. I am using a NSFetchRequest to do that but I was wondering if it is the right thing to do (one fetch request each time I populate a row).
Instinctively I would retrieve all the data I need in the NSFetchedResultsController, instead of searching for each translation each time I populate a cell, but I cannot figure out how.
Do anyone has some advice, or maybe some interesting links?

If each cell must display the Translation objects related to each Entity object, then you only need to walk the relationship from the fetched Entity object to the appropriate Translation objects.
Once you've fetched the Entity objects and then structured the table to display them, then to access the values in the translations for each cell row like so:
NSSet *translations=[anEntityObject valueForKey:#"translations"];
... which returns a set of Translation object for the Entity object represented by the tableview row.
As a very general rule, you only do one fetch per tableview. A table view should be configured to display data related to one particular entity.

Related

Most efficient way to join data from two views

Folks:
I have recently begun working with xPages. I have a view of documents that needs to present data from other related documents in six separated columns. What I am trying is to use a Computed column that does a lookup to a view with a concatenated string. My intention was to parse this into the 6 columns of data. It isn't working and it may be silly of me to try referring to a computed column in another computed column.
Another alternative was to have the underlying view present the UNID of the other document and then do a #GetDocField on the xPages view.
So I have two questions:
1) May I programmatically refer to a Computed column in a view from another Computed column?
2) For efficiency, what would be the best way to present data like a 'join' in a view?
I appreciate your attention and help.
Cheers,
John Collis
Can you try to “go native” ? You build one view that contains both documents arranged to be in that view after each other. So you have Type1,Type2,Type1,Type2 etc.
Then use a repeat control to render a table or list “joining” the two rows.
This would save you doing tons of lookups.
Eventually you use that view as Json Rest source to do the joining in Json
I would create a Java bean that returns a list of Java objects that contain your data.

Finding Lookup item numerical values in MS Dynamics

I have a site powered by ExpressionEngine 2.5.x, using Freeform, integrated to post form data to MS Dynamics CRM 2011. The extension is nicely scalable, I can change the mapping, all that excellent stuff. My problem is how to find mapping values for Lookup fields in MS Dynamics.
I am trying to map form fields from the site forms, into MS Dynamics. Some of the fields are Lookups, in MS Dynamics. Our mapping calls out the numerical value of the Lookup item, rather than its name. (Which is good, because ppl can change the text names in the MS Dynamics console without breaking the mapping.)
My question is: I know how to find the actual back-end field names of form fields within MS Dynamics. But how to I find the numerical values of the picklist items and lookup fields? Say I have a Lookup field, for Lead Source (called campaignid). The items are:
web
online
radio ad
flyer
word of mouth
other
I know that when I edit options in an option set, I can see their numerical value. Where can I edit options in a lookup field? I've tried looking under Settings > Customizations > Customize the System, but didn't see anything called lookup.
Lookups are pointers to entities. They do not have numerical values like regular option sets. So I guess that you will have entity called Campaign (or lead) so you can check which campaigns exist in the crm DB where each entity will have view in the DB.
Let's see if i understand your question. You don't have a Lookup option like Option Set because a lookup is consequence of a relationship 1:N between two entities. So for edit a lookup you need edit a record of a entity. In lookup fields you don't have numerical values, you have guid that represent individually a record, so in a record a lookup is stored in database as a guid. Check this video.
Check here how find this guid with the record open.
A look-up field is, roughly speaking a pointer to en entity (in C# it's referred to as EntityReference instead of Entity) and it consist mainly of a guid and logical name of something.
Usually, in the code, when you have an entity, in order to access the fields of its lookup-connected entity, you'll need to make an extra query for that.
So, if you have a Contact instance and need to see the address of its parent customer, you'll have to get the guid and logical name (in this case it'll be Account) and retrieve the data for it separately.
EDIT:
Suppose that you have created an instance of Contact entity and you'd like to access its lastName field. Then you can simply refer to it as follows.
var value = Xrm.Page.getAttribute(“lastName”).getValue();
On the same form, there's also a field that refers to an Account instance (its name is parentCustomerId. Suppose now that you'd like to get the fullName field of the Account. One could expect the following to work.
var account = Xrm.Page.getAttribute("parentCusomterId").getValue();
var name = account.getAttribute("fullName").getValue();
However, that's not going to work, because the parentCutomerId is a look-up field. It means that it only contains a guid (a pointer, a reference) identifying an other entity. You'll have to use it (the guid) in order to fetch the instance that the look-up is "mentioning". Then you'll be able to check it's properties.

Insert new data to a blank row in core data

I want to add data (string) to one of the blank row in core data (iOS). How do you do that?
e.g : I have an entity of STUDENTS and in that entity has 3 attributes : index, name, age. the 3 attributes are filled with data, let's say it has 10 row of data. But on index 9 the attribute of name has no data (blank space). How do you fill that blank space ?
I can't describe it clearly because I can't upload an image yet.
You shouldn't think of Core Data as a database with rows and columns. It is an Object Graph and Persistence framework. So you deal with Objects (like rows) and object properties (like columns). So once you have fetched or created some objects you set their properties.
If you haven't created NSManagedObject subclasses from your object model then you have to use the KVC accessors:
[student10 setValue:#"William" forKey:#"name"];
If you do create subclasses you can use Objective-C properties.
student10.name = #"William";
I recommend reading more about Core Data in the Apple Documentation to gain a proper understanding of the framework. They also have some tutorials I think.

With JPA, EclipseLink, JSF and reporting dynamically

I have 3 database tables and each table is represented by an Entity Class. What I want to do is to Join these three tables with a special condition and select maximum one column from each table wrap them in an object and display this object on the JSF tier using a data table.
Is it possible to do this using dynamic entity class without playing with my entity classes? Has anyone got a solution for this problem?
Will appreciate any help
Thanks a lot
You can use a constructor query, or just simply select multiple values and get an Object[] back.
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Constructors
You could also just select the objects, then extract what you need from them in Java.

Managing dates in Section Headers with Core Data

I have conceptual issue with using core data. My app lists events by title in the main tableview then navigates to a tableview which is unique to the event. Here it's supposed to display in the section headers of the tableview an event date, a list of dates that expand a range (requires calculation) or list of unique dates.
I have arranged this in the model with 3 entities. Event & Date have a one to one relationship. Date to Menu have a one to many relationship. Menu contains the data for events that have unique dates, Dates contains events that either have a start date or in some cases when it's a range an end date.
Ok if the above is clear my question is how do I do create a list of section headers unique to an event? Bear in mind that NSFetchedResultsController only provides the ability to return a section name from a managedObject. I think this is what's throwing me.
Do I fetch the data unique to the event then use FRC to create arrays to populate the section headers and live with the table not being managed? Or is there a smarter way?
I don't really understand your model but I think it looks something like this:
Event{
name:string
date<-->Date.event
}
Date{
event<-->Event.date
menus<-->>Menu.date
}
Menu{
date<<-->Date.menus
}
If this isn't correct, you might try editing the question with the data model in this format it can be better understood. (if you can't edit, just fold the format into a comment and I will add it. Alternatively, send it me in an email.)
I'm not clear on what data you want in your Event table section titles. Sections are intended to be groupings of managed objects based on some attribute of those objects. The canonical example would be Contact.app's contact list. The contacts are grouped based on alphabetical value of the first letter of the last name.
Once common mistake is to think of a section table as representing hierarchal objects with the section titles representing superior objects and the rows representing inferior e.g. yo have a model to simulate a file system so you have a Directory entity and a File entity. You try to set the section titles to the name of the Directory and the rows to the names of the related File entities. That would not work smoothly and would not really mesh with the interface grammar that the user has learned for section titles. Instead, you should have a hierarchy of tableviews with a table showing all Directory objects and then a second table view showing all the File objects related to the selected `Directory object.
So, if the section titles you want come from any object besides Event you are probably approaching the problem from the wrong angle.

Resources