Welcome, Guest
Username: Password: Remember me

TOPIC: J-cook and non id primary keys

J-cook and non id primary keys 20 Sep 2017 03:08 #15295

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Hello Admin/All
How can I quickly get j-cook to play nicely with a table which doesn't have a primary key named 'id'?
I am looking to maintain all the cook functionality on this table.
Thanks for any help
Warm regards
v
The administrator has disabled public write access.

J-cook and non id primary keys 20 Sep 2017 11:28 #15306

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
No, at the moment, you cannot remove the id.
Guess you are doing XREF and using 2 FK with unicity

I did some projects such you describe, and there is no problem at all, the ID is created with auto-increment, but never used.
Simply ignore it, and design your models to treat with the other ID fields.

Can you describe more precisely where you encounter problem ?
Coding is now a piece of cake
The administrator has disabled public write access.

J-cook and non id primary keys 20 Sep 2017 14:30 #15309

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
WHAT I AM DOING:
I am using cook to build mobile connections to Joomla and need to interact with the session table. This way I can keep the users connected even if the devices go to offline mode and return. The simple way would be to use the $query object, but prefer homogenous code. So in the end I took an hour and coded a best-fit solution.

What I found is that JDom has a heavy bios towards "id" and integer primary keys. This is hard coded and enforced by the use of "x = (int) $id" in some areas, but ought not to be so. Would love to see cook revisit this doctrine and offer developers the option to declare the key-name in the table class and then use that definition throughout the solution.

Fork table file:
public function __construct(&$db, $tbl = '#__session', $key = 'session_id')
{
	JTable::__construct($tbl, $key, $db);
}
The solution I ended with can instance the list and item classes and display the list only. The fact that cook can't handle alphanumeric keys makes it "impossible" to view a single item without rewriting much of the cook code. Viewing/editing a record is not a requirement on this table anyway, so I'm happy with the final product.

This may seem trivial, but if one needs to determine/display the status of a user or anything like that, this is the go-to table. Cook should allow for easy integration of this important resource.

This is the code for retrieving the user-session:
$model = CkJModel::getInstance('Sessions', 'XModel');
$model->setState('filter.userid', 'auto');
$sessions = $model->getItems();
Best regards
v

PS: wanted to test my status as an Elite Member. :lol:
The administrator has disabled public write access.
Time to create page: 0.090 seconds

Get Started