Welcome, Guest
Username: Password: Remember me

TOPIC: Moving parts for RELATIONS

Moving parts for RELATIONS 02 Dec 2015 23:44 #13700

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
What pieces of code manage the relations.

I have a component well underway, and dont have time to deploy and fix a new download of JCOOK. However I am pulling in all the things that I think make a relations FK and it just wont work.

What files beyond the obvious MODEL contain code. All my other relation FK's work except this one which appears to be funcxtional, but has no items to choose from.

Are there any files beyond the actual function in the ADMIN sections for instance?

When I look at my debug screen, I do not see the query for pulling in the data for that relation.

In sandbox its fine, and I have pulled in all the SITE files from a new installation.. so I am thinking there is something in admin. The database is also correctly created,
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Moving parts for RELATIONS 03 Dec 2015 13:03 #13705

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 985
  • Karma: 140
Search for 'relation' in a fresh downloaded component, you will get all the functions involved.

Most are located in model superclass.

Not exhaustive (can be incomplete):
Declarations:
local var $relations in the model (cache var)
Functions:
newRelation()
hasMany()
hasOne()
belongsTo()
belongsToMany()
(This is the conventions names are inspired from Nicholas Dionysopoulos to keep same conventions than FOF, but also because they are good syntax)
prepareQueryRelations()

To get the relations maps :
$model->getRelation($name);

To populate a cross reference:
$model->loadRelation($name);

To save the relations:
$model->syncRelation($name, $values);

To implement it :
Override of ModelItem::save() in the superclass
Override of ModelList::__construct() in every list model (Relation definition)

Relation definition.
Cook Uses exactly the same than FOF, so when you build for FOF the component stay consistent.
See there for learning how to configure: github.com/akeeba/fof/wiki/Model-relations


The only thing on top is the select[] array, wich defines the list of fields to include in the 'select' query.
Very usefull in our case. (the FIRST field name in select[] is took as default fallback when you do not specify in the caller)

Fields (model/fields)
- model.php
- relation.php

Note : loadXref() and updateXref() are deprecated (old system) Do not use them.

Views:
To load a cross reference, you NEED to call, in the view:
$model->loadRelation('myRelation');
AFTER $model->getItem(); or plural : $model->getItems();
Have a look how displayXxx() is written with that.



Hope it helps. It is difficult to remember it the whole thing.
Then see if you get PHP errors for missing some things (maybe your old version is missing other functions)
Coding is now a piece of cake
The administrator has disabled public write access.

Moving parts for RELATIONS 03 Dec 2015 15:00 #13712

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
Just wierd.

I have put everything in place.. easily done, but this box just will not work.. it is aslking for options, but the list is just empty as the model is not being called.

I would download a new version, but even on SANDBOX mode, I am having even MORE problems and NONE of my FK Relations will work (I rasied a ticket for that one)
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Moving parts for RELATIONS 03 Dec 2015 15:02 #13713

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 985
  • Karma: 140
Already done ?
Fast.

I am actually checking your other ticket.
Coding is now a piece of cake
The administrator has disabled public write access.

Moving parts for RELATIONS 03 Dec 2015 15:17 #13714

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 16
No, just cant get it to work, even though I see thje principal is VERy easy.

I am just awaiting your finding on the ticket, then I will most likely just install a new downloaded version
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.
Time to create page: 0.103 seconds

Get Started