sproutcore orderBy other controller - sproutcore

in one of my ListViews I display besides several 'office' properties a 'distance' property belonging to an other controller and the orderBy is only working for/with the 'office' model properties.
Background: I have an input field for an postalcode used in a query to get the distances between this postalcode and all of our office postalcodes. The obtained distances are in a second controller.
Please some advice how to get the distance orderBy working.

The easiest would be to add a computed property to the model which retrieves the distance from the controller in which you have the information. In order for the orderBy to work, it needs to seem to the array controller / list view combination that the property you want to sort on is a property of the object displayed.

Related

Filemaker Pro display a name instead of id for multiple fields with the same relationship

I have a two color fields in my Product table. They both are IDs that map to the Color table with a description. I know the idea with Filemaker is to have 2 fields for this, one for display and one to hold the id. However, I can't get a display field to know which colorid to map with, and therefor nothing shows up.
It sounds like you might have your relationship defined with BOTH colorID fields connected to the Color Table. So there is only one relationship that is using two key fields. If that is what you have then, that is your problem.
To fix it, you will need two relationships. One for each Color ID field in your Products table. Name them something like "Product Color 1" and "Product Color 2". Then setup your two display calc fields to use those two relationships respectively.
I can't tell from your description what's missing in your setup, so let me describe what you should have:
Table Colors:
ColorID - a unique id field (preferably auto-entered serial number);
...more fields describing the color ...
Table Products:
... fields describing the product ...
ColorID1 - a Text or a Number field (match the type to Colors::ColorID); nothing auto-entered;
ColorID2 - same as ColorID1;
On the Relationships Graph, create two new occurrences of the Colors table and name them "Color1" and "Color2". Define the following two relationships:
Products::ColorID1 = Color1::ColorID
Products::ColorID2 = Color2::ColorID
Define a value list using the ColorID field from Colors, also showing [some field that helps to select the color]. Attach this list to the two ColorIDx fields on the Products layout.
Place some fields from the Color1 and Color2 occurrences onto the Products layout; make them non-enterable in Browse mode to prevent accidental modification.
Now, when you select a color in either of the two ColorIDx fields, the related fields you have placed on the layout will populate with data from the corresponding related records.
There are some assumptions being made here:
each product has exactly two colors;
it is important to know which color is #1 and which is #2 (otherwise
we could have used a single relationship and show the two colors in a two-row portal, in no particular order).

ListItemRenderer 'data' parameter

I am using Listitemrenderer(Zk UI and Grails) to render a list of books from database table called "book". I have different types of books in the table. the book types are determined by the bookType attribute. The issue I am having is that when I do:
Book bookInstance = (Book) data
it shows null point exception when there are different types of books in the table. But in the case when there are books of a single type, it works fine.
Is there a way to filter the parameter 'data' of Listitemrenderer so that I could get books of a certain type I want? Again, there is an attribute bookType in database table that distinguishes different types of book.
Thank you!!!
you can use Query String with 'where' clause specifying 'book_type'.
this way use can fetch the desired result.

CoreData -to many relationships

I'm beginning to use Core Data and I'm trying to get a solid understanding of how it would work in my case. I'm building an iPad photo album app that will allow users to filter their results based on keywords and a couple of other attributes associated with each photo. The attributes would be basic stuff like orientation and whether its color or not. Keywords will be based on a set of defined values that the user will have to choose from.
Here's a rough outline of what I have in the Core Data Model so far:
Entities (attributes):
Photos (id, title, desc, file path)
Keywords (id, name)
Since a photo can have multiple keywords associated with it, do I create a relationship from 'Photos' with a destination of 'Keywords' and make it a -to many relationship? Is that correct/crazy/completely wrong? How would I go about adding/fetching records for that relationship?
If the Keywords are defined and the user can choose them from a defined list, I wouldn't have used an entity Keyword. Tip always use singular names (Photo, Keyword). I would have the keywords in a plist and the user chooses a few, you could then create a comma separated string to save as a property on Photo. As Joseph mentioned, you want to subclass NSManagedObject and I would then add a method that receives a string (keyword) and returns a BOOL indicating if that keyword was part of the comma separated keyword values on the Photo property
This is correct. There are several approaches to accessing this, but the most straight-forward way is to generate NSManagedObject subclasses (Editor->Create NSManagedObject Subclass...). When populating these the Photo entity, the Keyword relationship will be populated in the property called keywords.

Entity Framework 4.0, PoCo & Navigation Properties for Lookup Tables

I have the following Models
DeltaDirectionType,
int Id
string Name
Delta,
int Id
string Name
DeltaDirectionType DeltaDirectionType
Double Value
Trade
int Id
DateTime BusinessDate
IList<Delta> deltas
So DeltaDirectionType is a lookup table, Trade holds a collection of Deltas
In the database it is implemented as follows
DeltaDirectionTypes
Id int
Name varchar(max)
Deltas
Id int
Name varchar(max)
DeltaDirectionType_Id int
Trade_Id int
Value float
Trades
Id int
BusinessDate DateTime
Delta_Id int
When I generate the model from code for the Edmx file, and (un check the foreign keys) as my model does not have properties for these. I am having problem with the navigation properties. Something like this in nHibernate would be a simple one to many mapping for the DeltaDirectionType and Delta and a many to many for Delta and Trades however, how do I firstly get it to recognise that DeltaDirectionType is a lookup and secondly get the Icollection to work for me.
I am struggling with this, Entity Framework does not make it easy for you. I have tried the usual, delete the navigation property that EF puts in for you on one side, but then you get some mapping fragments errors, properties not mapped etc.
Please help or point in the right direction.
Lookup tables are real life problems, not sure why it is so hard withing EF to implement.
Any help much appreciated
Thanks
You must either create foreign keys or navigation properties in the model to navigate the relationship.
Navigation properties can be defined as one-way, ie from the deltas table to the look-up table. A one-way navigation like this would add the appropriate property to the delta's object but not to the looup table
What you actually mean by lookup? Do you except that Delta entity will have DeltaDirectionType_Name directly mapped?
In EF you will get navigation property to DeltaDirectionType and you can access the name through this navigation property. If you don't like it you can add new property to partial class of your generated POCO and provide the Name directly in Delta entity like:
public string DeltaDirectionTypeName
{
get
{
return DeltaDirectionType != null? DeltaDirectionType.Name : String.Empty;
}
}
The only problem is that you can't use this property in Linq-To-Entities queries. In queries you always have to use navigation properties.

Is it possible to sort a TDBGrid on a lookup field?

I have a DBGrid with a column based on a lookup field.
How can I set it up so that when a user clicks on the column title, it will sort by that field.
My problem here is that I can't figure out a way to create an index on a lookup field.
I'm using Absolute Database for this, but most things that work with the BDE or TClientDataSet will work with Absolute.
Thanks!
I don't think it is possible to create an index on a lookup field. It is possible to create an index on an internally calculated field of a ClientDataSet though. In the OnCalcFields event handler set its value to the value of the lookup field. And set the visible property of the lookup field to false. Now you can sort on the internally calculated field.
What you could do (especially if the data is readonly, and does not have zillions of rows) is use a ClientDataSet to display data in your grid.
Roughly the steps would be like this:
Load the data from your regular into the ClientDataSet,
add a calculated field to the ClientDataSet that contains the value obtained from the lookup,
then add an index to that calculated
field.
--jeroen
You cannot sort by a lookup field. But you can 'fake' this. Let's suppose that you have the following tables: (PK means Primary Key)
Contacts
ID - Integer (PK)
NAME - Varchar(40)
COUNTRYID - Integer
Countries
ID - Integer (PK)
NAME - Varchar(40)
Then you can have the following query in the dataset which is linked to the TDBGrid:
SELECT C.ID, C.NAME, C.COUNTRYID, CO.NAME
FROM CONTACTS C
JOIN COUNTRIES CO ON C.COUNTRYID=CO.ID
(Not tested but I think that you got the idea)
Also you can put this in a view.
Then you'll display in your TDBGrid (as columns) only the ID, NAME and the desired lookup field which you already have (let's call it COUNTRYLOOK).
When one clicks on the Title Header you can change the query by adding in the 4th line an ORDER BY . For the specific column of the lookup field (COUNTRYLOOK), instead of using the 1:1 mapping you can put in the 4th line of your query ORDER BY CO.NAME. Reopen the query and that's it. In practice is much more simpler than my description here.
DevExpress ExpressQuantumGrid can do it, check it out:
http://www.devexpress.com/products/vcl/exquantumgrid/

Resources