Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Catalyst and ExtJS : Using Table Relationships

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


jagdish.eashwar at gmail

May 24, 2009, 8:11 AM

Post #1 of 2 (350 views)
Permalink
Catalyst and ExtJS : Using Table Relationships

Hi,

I am trying my hand at using Catalyst and the ExtJS Grid (instead of TT). I
am able to fetch data from a single table and display them in the grid. But
I am not able to figure out how I can use the table relationships to fetch,
say, the corresponding item_name for a given item_code and display that in
the grid instead of the item_code.

If I use TT, I use the following to fetch the item_name from another table
in the schema:

[% FOREACH item IN item_stash %]
[% item.belongs_to_relationship.item_name %]
[% END %]

How is this to be done when one is using the ExtJS Grid? I'm following
mainly Jason Kohles' tutorial which is available at
http://www.catalystframework.org/calendar/2007/9.

Jagdish Eashwar


peter at peknet

May 25, 2009, 11:31 AM

Post #2 of 2 (296 views)
Permalink
Re: Catalyst and ExtJS : Using Table Relationships [In reply to]

jagdish eashwar wrote on 5/24/09 10:11 AM:
> Hi,
>
> I am trying my hand at using Catalyst and the ExtJS Grid (instead of TT). I
> am able to fetch data from a single table and display them in the grid. But
> I am not able to figure out how I can use the table relationships to fetch,
> say, the corresponding item_name for a given item_code and display that in
> the grid instead of the item_code.
>
> If I use TT, I use the following to fetch the item_name from another table
> in the schema:
>
> [% FOREACH item IN item_stash %]
> [% item.belongs_to_relationship.item_name %]
> [% END %]
>
> How is this to be done when one is using the ExtJS Grid? I'm following
> mainly Jason Kohles' tutorial which is available at
> http://www.catalystframework.org/calendar/2007/9.
>

Presumably when you serialize your data into JSON, just use the foreign table
value you want instead of the foreign key.

CatalystX::CRUD::YUI implements this with the ExtJS livegrid extension, using
Rose::HTMLx::Form::Related.

Basically, each Controller corresponds to one table, and each table has one ORM
(DBIC or RDBO) class and one Form (RHTMLO) class. The Form class builds an
internal metadata structure for serializing a table row using unique values from
foreign (related) tables instead of the foreign key value.

So for example, if you had a db like:

create table persons (
id serial primary key,
name varchar(255) not null
);
create unique index person_name on persons(name);

create table users (
username varchar(16),
person_id int not null references persons(id)
);
create unique index user_username on users(username);

where each Person can have one or more related User records, every time the User
Form is serialized it displays the person.name instead of the users.person_id.

The unique value is defined in each ORM class (DBIx::Class::RDBOHelpers for DBIC
and Rose::DBx::Object::MoreHelpers for RDBO) with the unique_value() method,
which by default looks for the first single-column unique column in the table.


--
Peter Karman . http://peknet.com/ . peter[at]peknet.com

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.