[baseten-users] Baseten Examples

Tuukka Norri tuukka.norri at karppinen.fi
Thu Sep 10 00:44:04 EEST 2009


Hi!

Michael Ruepp kirjoitti 2.9.2009 kello 2.39:
> 1. I want to populate two nstableviews. I can create objects in  
> table_a, and when I create objects in table_b, these will be in  
> relation to the selected object in table_a. So when I select object  
> in table_a, I want table_b to show all related objects to object in  
> table_a.
>
> I am really stuck, messed around with bindings, tried to populate  
> the contentarray of table_b by binding it to the table_a with  
> selection and baseten name of the relationship, no success.
> Is such a solution possible entirely in interface builder with  
> bindings?
First create a BXDatabaseContext and set its database URI using IB's  
inspector. Also create two BXSynchronizedArrayControllers. Set the  
tables' names in the array controllers' settings and set only the  
controller for table_1 to fetch automatically. Also set the array  
controllers' databaseContext outlet to the database context or bind it.

Now bind table_2's array controller's content set to table_1's array  
controller. Controller key should be set to “selection” and model key  
path to the relationship's name. It's probably called “table_2Set” but  
use BaseTen Assistant's inspector on table_1 to verify this.

Finally drag two table views to windows of your choice. Bind columns  
in each to one array controller. (Don't use the table view's “Content”  
binding but the table columns' “Value” instead.) The controller key  
should be set to “arrangedObjects” and the model key path to the  
property name that you used in your object model.

I'm writing this from memory, but this is how I expect things to work  
anyway.

> How can I tell the add button of table_b to use the relationship to  
> the selected object in table_a and to check first if an object is  
> selected?
Just set the button's action to the corresponding array controller's  
add: action. (You can use insert: as well but it doesn't really insert  
the object, since row order in database isn't preserved.) In case the  
array controller's contentSet is bound, objects are added to the  
relationship automatically.

If you set the button's “Enabled” binding to the table view's “canAdd”  
property, the button should become disabled when there aren't any rows  
selected, but this actually depends on NSArrayController's  
implementation.

> 2. How can I achive the same setting, but show the data in a  
> NSOutlineView or NSBrowser? Do I have to connect to a  
> NSTreeController? And how can I do that?
These are a bit more difficult in the sense that each object should  
have a method for retrieving a collection of child items. We don't yet  
have a general-purpose solution for this since there's more than one  
way to represent this in a database.

> 3. I would be very thankful if someone could write the baseten  
> tutorial maybe with two tables and a one to many relationship or at  
> least with one table entirely in code. There exists so few examples  
> for coding, I´d appreciate it very much because the learning curve  
> would be much faster when seeing the code and at least more complex  
> examples.

We actually were planning to add a tutorial on relationships but then  
became extremely busy with everything else. I'll try to make a simple  
nib to demonstrate this tomorrow.
-- 
Best regards,
Tuukka Norri
MK&C



More information about the baseten-users mailing list