PDA

View Full Version : Display 1:1 relation between models in a Grid / Associations



mik3e
6 Feb 2012, 4:20 AM
Hi there,

Iīm trying to display a 1:1 relation between two models in a grid (one row). Hereīs the problem Iīm trying to solve:

The problem:

Model 1: Credential (Login data for a character - password + email)
Proxy: REST

Model 2: Character (Data of a human being - firstName + lastName)
Proxy: REST

Now in the backend we need a Grid view called "User" which shows all users of the system in a list. A User is a join of a Character and a Credential and doesnīt physically exists in the data model.

What I want to get:

ExtJS Grid with the following content:
-------------------------------------------------
1 FirstName LastName email password
-------------------------------------------------
2 FirstName LastName email password
-------------------------------------------------
3 FirstName LastName email password

So as you see I want to get a "User" list which is generated with ExtJS mixed up of credentials and characters.

Of course you could say: "Hey, just implement a http://domain.com/User REST interface on you server side which does the work for you". Thatīs correct, but I want to have a look if there is a convenient way to show the data on the client side.

I already tried different solutions with hasMany and belongsTo and read many articles in the forum, but I didnīt find a solution for that till now.

Thanks for any ideas,
Ciao,
Mike

tvanzoelen
6 Feb 2012, 4:34 AM
I think that associating thing with models isn't much evolved yet. What I know about it is that you define a grid with the usermodel behind it.

You define four columns (two extra for the credentials) in the grid. In the columnrenderers for the credentials, you lookup the values in the credential model and display it with code in these columnrenderers.

mik3e
6 Feb 2012, 4:45 AM
Uh.. that breaks the sense of usage a bit. So it would be really better to implement a user object on the server side ...

mik3e
6 Feb 2012, 4:58 AM
Hm, on the other side the "virtual" user object on server side is also not a nice solution. Cause as the REST standard defines, each URL represents a "real" ressource - and user is not a real ressource in the system.

So Iīll try the way youīve suggested first...

tvanzoelen
6 Feb 2012, 5:04 AM
Sorry, Its a bit different as I said. You put the user model under the grid. So no extra columns for the credentials but for the columns of the foreignkey in the usermodel you add a columnrenderer that looks up the associated value in the credentialsmodel.

See http://www.sencha.com/forum/showthread.php?139172-Grid-column-field-value-from-model-association