AshishJoshi-asj / zfdatagrid

Automatically exported from code.google.com/p/zfdatagrid
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

CRUD model referencing other field in parent table #152

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create table "users" that has numeric ID and a string Username
CREATE TABLE `users` (
  `id`         int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username`   varchar(50)
)

2. create second table referencing "users"
CREATE TABLE  `addressbook` (
  `id`         int(11) unsigned NOT NULL AUTO_INCREMENT,
  `userID`     int(11) unsigned NOT NULL,

  KEY `idx_addresbook_userID` (`userID`) USING BTREE,
  CONSTRAINT `fk_addresbook_users` 
    FOREIGN KEY (`userID`) REFERENCES `users`(`id`)
);

3. in Addressbook's table class set _referenceMap
protected $_referenceMap = array(
  'User' => array(
    'columns' => 'userID',
    'refTableClass' => 'users',
    'refColumns' => 'id'
  ),
);

4. open Addressbook Form

What is the expected output? What do you see instead?

In Form there are dropdown numbers for field UserID (ids from table Users).
However, I'd like to see field Username from table users, not ids.
Select box like (even better just names):
1 - John
2 - Marry

Is that possible to achieve without something like following

$stmt = $db->query("SELECT id, username FROM users");
$userIds = $stmt->fetchAll();
$userId->values($userIds);

What version of the product are you using? On what operating system?
0.6alpha

Please provide any additional information below.

Original issue reported on code.google.com by vlatko.b...@gmail.com on 11 Feb 2010 at 1:49

GoogleCodeExporter commented 9 years ago
Hi,

Your are saying that the refColumns id is reflection of UserID. 

Shouldn't this be

    protected $_referenceMap = array(
      'User' => array(
        'columns' => 'userID',
        'refTableClass' => 'users',
        'refColumns' => 'username'
      ),
    );

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 11 Feb 2010 at 3:27

GoogleCodeExporter commented 9 years ago
Hm, I do not know what happened, but I tested that before. Display was fine, in 
Grid
and in Form, but submitting the Form caused an SQL error (something like 
'Uganda' is
not numeric value). 

I really do not understand how!??

However, now it works fine. Both Grid and Form. Sorry I took your time. :-(

Original comment by vlatko.b...@gmail.com on 11 Feb 2010 at 5:55

GoogleCodeExporter commented 9 years ago
No problem...

Original comment by pao.fre...@gmail.com on 11 Feb 2010 at 6:37

GoogleCodeExporter commented 9 years ago
Verified

Original comment by vlatko.b...@gmail.com on 16 Feb 2010 at 12:01

GoogleCodeExporter commented 9 years ago

Original comment by bento.vi...@gmail.com on 3 Mar 2010 at 4:56