Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
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

Please Log in or Create an account to join the conversation.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

Please Log in or Create an account to join the conversation.

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

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
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:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.100 seconds

For starters it's just so easy to design an app in a way that I'm used to i.e. database first then views followed by customization. The fork system is pure brilliance from a developer standpoint as I can override things and still add and update my projects with minimal effort! Truly amazing to be able to build components in Joomla using incremental refinement without having to do everything by hand. Thanks for the great tool! I am so much more productive now than ever and I can't imagine building components any other way!!!!
Dave (Forum)

Get Started