Use "Custom Data Object" for non-Customer/Company related information - eloqua

When I create Custom Data Object, it asks to set "Default Entity Mapping used in upload". What should I use if I want to store only product information (not who bought what)
Is it possible to create a "Custom Data Object" to store non-Customer/Company related information?

Absolutely, none of the data has to map back to any contact or account record. Even if it happens to match (unlikely, unless you design it as so), there is no harm to your CDO or contact records.
However, if you're not looking to map it to another record, then what is the use case?

Related

Core Data: change delete rule programmatically

My iOS app downloads record from a 3rd party database, and stores them locally using CoreData. The user is able to edit some aspects of the stored records, eg user notes can be added in addition to notes from the database.
Occasionally, the database gets updated, and I provide a refresh function. Instead of checking what parts of the entries are different, I just brute-force remove the old one and replace it with a new one.
However, this also removes the user notes. I tried saving them before the refresh, and re-adding them after inserting the new entry, but once the original entry gets deleted, the user note is also deleted because of the "Cascade" delete rule. If I set the delete rule to "No Action" for notes, then all notes will not be deleted.
So I was thinking, is it possible to temporarily change the delete rule of the user note while updating so that it doesn't get deleted with the old entry?
Or maybe my approach is completely wrong, and there are better ways to handle this?
UPDATE: I have created a follow up question here: Change relationship of NSManagedObject to different context
You are not allowed to change model after it was instantiated, except versioning.
The way I think, you should create new entity, say, CustomNote and store some unique identifier to original "record". Then just retrieve this notes by id.
Although, it may be some more advanced approach with relationships, this is the simplest.

Keep reference of ABPerson in CoreData

I'm trying to keep the phone's contacts in my app up to date, in a persistent way. For that I'm thinking of using Core Data.
My plan right now seems highly suboptimal :
Browse the address book and every ABPerson in it
Store every field in a CoreData persistent store
Store the image in a separate file with an unique name and a reference in another "Contact" field.
And I do this every time the app comes in foreground in case the user would change one of his contact's name or picture, etc.
Some of my users have more than 2500 contacts, sometimes the operation lasts up to 10 seconds.
My question is :
Is there a way to keep some kind of reference to my ABPerson in coredata, so I can always load my ABPerson properties everywhere instead of Contact properties? (which would then always be up to date).
And I'm not even sure it's the right decision :
Should I always use the ABRecord that I find with a reference?
Should I always use my own copied data that I update regularly (from the ABAddressBook)?
If not, do you guys think I'm doing this in a decent way or would you suggest something else?
EDIT:
As asked in the comments:
I need to keep the contacts up to date simply to use their firstname, lastname and picture properties. If I notice the ABRecord changes, I'll update the related custom objects accordingly and that's it. I won't really need anything else afterwards (until they're edited again)
Thanks
Obtain and store only the ABRecord's unique identifier value. This is the one persistent way to reliably refer to the same person repeatedly and consistently.
You can always get all the other info out of the contacts database by using this unique identifier.
In iOS, call ABRecordGetRecordID to obtain the person's unique ID. Store that. When you later want to obtain the corresponding person, call ABAddressBookGetPersonWithRecordID.

What is best practice to handle Core Data relationship if I don't have the full data-set?

I have two type of models in the application I'm working on: User and Account.
Every account has many users. Every user has one account.
When I download the user object from an API, I get the account_id, but not the actual account object. The account object will be downloaded after the user object.
What is the best practice for establishing the relationship between the user and his account in this situation?
Should I insert an empty row into the Accounts table with just its account_id field filled in? And then later, when I download the account, update that row?
First, Core Data centric definitions, you have 2 entities (User and Account) and no tables (because this is an object store, not a SQLite database).
So, you wouldn't have empty rows, you would have stub objects (partially complete objects that will be filled in later).
There is no best practice when it comes to stub objects. Whether you should create them is entirely dependent upon your use case. In some cases it helps to have the basic information about an item so that you have something to show the user while you go and get the details. In your case, you only have an identity so the benefit of stub objects seems very low.

Core Data Relationships and saving/fetching

I'm a little confused about the core data mechanisms with respect to object relationships.
I have an "Account" model, and a "Credit Card" model, and I have two questions:
How do I set up a one-to-many relationship from Account to Credit Card and a one-to-one relationship from Credit Card to Account? I'm having trouble figuring out exactly how to set that from the data model in XCode.
If my Account model has a Credit Card property (or an NSSet, it looks like), and I set that property and save the account object, should the Credit Card object associated with it be saved as well? Or does that need to be saved separately? What's the proper way to do this? Conversely, what's the proper way to fetch objects in such a relationship, and to modify and replace them in the core data store, rather than simply inserting?
I know these are pretty basic core data questions, so thank you in advance for your patience.
You need to read this guide. Probably you should change the display style in Xcode to be table based rather than the diagram style.
You don't save individual objects, you save the store as a whole. So all changes are saved at the same time.
When you have an object with a relationship it is presented to you as a set (NSSet as you say). You can iterate that set to find and modify the destination objects, you can also filter the set to find specific objects. You can also run fetch requests with predicates to find the objects you want to modify. There are many options.

storing number of yet nonexistent objects in relationship in Core Data

I have some data that needs to be loaded from the server (backend). For example, let's just say I have an entities of user and event. The relationship between them is many-to-many (user can attend many events and event can have many attendees). All the data is stored remotely on backend and locally in Core Data. When I download data from backend I convert it into NSManagedObjects and store it in NSManagedObjectContext. Everything's very simple, but...
When I download a list of events I want to know, how many attendees this event has. But I cannot download a list of users in the same request, because it's totally overkill. What I need is to download, let's say, a list of users' unique ids so that I can have two things: total number of attendees and means to download detailed data of concrete users (via unique id). Or there's another example: I need to know total number of attendees and download a limited set of them, so I can create some entities in CoreData, but not all of them.
So the main question is how am I supposed to store such information in my CoreData? Meaning I need to know that for some entity there are some related entities in relationship that are not actually currently present in CoreData, but I know how many of them there should be. The first thing that came in my mind is to have a attribute called something like usersCount in my event entity, but that seems to be kind of dirty. What is the best practice for such situation?
Please comment if the question is not clear enough so I can maybe add some more specifics.
When you download an event with a list of corresponding user ids, then you can create
the Event object and also the related User objects, but you fill only the "userId"
attribute in the user object.
Later, when you download the complete user info, you update the existing (incomplete) objects
or create new user objects. Implementing Find-or-Create Efficiently in the "Core Data Programming Guide"
describes a pattern that might be useful.
So the idea is to create Core Data objects with incomplete information first and update the
objects with detailed information later. The advantage is that you can set up all relationships immediatly, and e.g. counting related users works even if the user information
is yet incomplete.
There is nothing dirty about having an attribute to store the count, especially if those entities are retrieved and paged via separate requests.

Resources