Skip navigation.
 
mlRe: Core data model, bindings advice.
FROM : Steven Hamilton
DATE : Thu May 15 11:51:10 2008

Hmm, now I've done a bit more research (my heads puggled with it 
all ;) ) I believe none of those options are appropriate.

Taking a more basic look at the issue the solution appears quite 
simple. I have an entity that contains data. I have a table that needs 
to display that data in a slightly different manner. Therefore I need 
to change that data on the way to the table. So, I believe I need a 
custom datasource to pull (or fetch) from my Core Data entity and 
formulate the data into a new array. I then bind my tableview's array 
controller to this datasource. My datasource also has to work in the 
reverse direction and update the model with new data from the tableview.

Of course, its easy using pseudo speak to describe something. It's 
another actually making it happen.

On 14/05/2008, at 9:53 PM, Steven Huey wrote:

> Steven,
>
> On May 13, 2008, at 5:12 AM, Steven Hamilton wrote:
>

>> How would I best handle translating the data from the entity model 
>> to the view model? I see two options;
>>
>> 1) Munge around with Valuetransformers. If toAccount = selected 
>> account then credit = amount, debit = blank, opposite if 
>> fromAccount = selected account. I still have the add: issue.

>
> I don't think this is the intended purpose of ValueTransformers.
>

>> 3) Would a filter be more appropriate? Is it possible to filter the 
>> transaction list and use the account selection (from the tree view) 
>> in the filter predicate?

>
> Take a look at NSPredicate. If you have your entities in an NSArray 
> you should be able to filter that using an NSPredicate in memory 
> very quickly. You could then use the results in your table view.
>

>> On 13/05/2008, at 12:27 AM, Steven Huey wrote:
>>

>>> Steven,
>>>
>>> In my app I have a similar setup, although without the detail view.
>>>
>>> I have the Table Column of my NSOutlineView bound to a 
>>> NSTreeController using the Controller Key "arrangedObjects" and 
>>> the Model Key Path set to the name of a method in the custom 
>>> NSManagedObject subclass that my NSTreeController is managing.
>>>
>>> The table columns of my NSTableView are bound to an 
>>> NSArrayController whose content set is bound to my 
>>> NSTreeController's selection. Each column is then bound to a 
>>> property of the entity returned by the array controller's content.
>>>
>>> I think you could bind your detail view similarly, to the current 
>>> selection of your array controller.
>>>
>>> Take a look at: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
>>>  for lots of great examples of how to use bindings.
>>>
>>> Best regards,
>>> Steven Huey
>>>
>>> --
>>> Steven Huey Software - http://www.stevenhuey.com
>>>
>>> On May 12, 2008, at 8:03 AM, Steven Hamilton wrote:
>>>

>>>> Hi folks,
>>>> Continuing my learning into Cocoa I'm developing a personal 
>>>> finance application. An admirable project I believe since none 
>>>> available suit my purposes and it always pays to have a project 
>>>> that one would use to learn from.
>>>>
>>>> I have a simple core data model consisting of AccountGroup, 
>>>> Account, Transaction and I've jammied these all into a window 
>>>> with outline view, transaction tableview and detail at the 
>>>> bottom. The model looks like this;
>>>>
>>>> AccountGroup (Asset, expense, income etc)name (string)
>>>> accounts (relationship to Account)Account (Bank, Savings etc)name 
>>>> (string)
>>>> transactions (fetched properties explained below)
>>>> credit (relationship to transaction)
>>>> debit (relationship to transaction)Transaction
>>>> memo (string)
>>>> date (date)
>>>> amount (NSNumber)
>>>> fromAccount (reverse of debit)
>>>> toAccount (reverse of credit)
>>>> I believe this to be the true model as a transaction is an object 
>>>> and is of an amount that goes from somewhere to somewhere. This 
>>>> is double entry accounting. My problem is in presenting this to 
>>>> the user.
>>>>
>>>> Problem 1
>>>>
>>>> Most finance apps, and mine included you select an account from a 
>>>> list (my outlineview) and it then displays all the transactions 
>>>> involved. So I created a fetched property with a predicate that 
>>>> included any transactions that had the selected account name in 
>>>> either fromAccount or toAccount. This works to a point. My 
>>>> tableview displays all the transactions of the selected account 
>>>> but since its a fetched properties (contentArray) the list isn't 
>>>> the true transaction array (contentSet), therefore I cannot add 
>>>> to it using the bound detail table below it.
>>>>
>>>> I must admit the bindings for this are really playing with my 
>>>> head. I struggled quite immensely getting the selection from the 
>>>> treecontroller and in the end it started working without me fully 
>>>> understanding why. I have further complications to come as I have 
>>>> the decide whether the transaction amount is a debit or credit 
>>>> (based on the from/to account relationships) and then display the 
>>>> amount in the correct column and then also work out a way to add 
>>>> transactions back in like this.
>>>>
>>>> It seems even though I'm set on what I believe to be the correct 
>>>> data model for this, the method of which a user expects to see 
>>>> this information is a little too different. Does anyone have any 
>>>> advice? Have I talked too much?
>>>> _______________________________________________
>>>>
>>>> Cocoa-dev mailing list (<email_removed>)
>>>>
>>>> Please do not post admin requests or moderator comments to the 
>>>> list.
>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>
>>>> Help/Unsubscribe/Update your Subscription:
>>>> http://lists.apple.com/mailman/options/cocoa-dev/steven.<email_removed>
>>>>
>>>> This email sent to steven.<email_removed>

>>>
>>>
>>>
>>>
>>>

>>

>
> --
> Steven Huey Software - http://www.stevenhuey.com
>
>
>
>

Related mailsAuthorDate
mlCore data model, bindings advice. Steven Hamilton May 12, 14:03
mlRe: Core data model, bindings advice. Steven Huey May 12, 16:27
mlRe: Core data model, bindings advice. Steven Hamilton May 13, 11:12
mlre: Core data model, bindings advice. Ben Trumbull May 13, 21:46
mlRe: Core data model, bindings advice. Steven Huey May 14, 13:53
mlRe: Core data model, bindings advice. Steven Hamilton May 15, 11:51