Posted: Thu Aug 31, 2006 7:04 pm
This is going to be short and sweet, because I thought I had already posted it. But I must have hit the close tab at some point. So here we go:
I currently have 4 tables of import. R_ (relationships), D_TASK, D_NOTE, D_SUGGEST (D_ means data). Every D_ has a field named ID, primary key, auto increment, mediumint, not null, unsigned, zerofill. R_ looks like this:
-----------------------------------
CREATE TABLE `R_` (
`PNAME` varchar( 10 ) NOT NULL,
`CNAME` varchar( 10 ) NOT NULL,
`PID` mediumint( 8 ) unsigned zerofill NOT NULL,
`CID` mediumint( 8 ) unsigned zerofill NOT NULL,
`OID` mediumint( 8 ) unsigned zerofill NOT NULL default '00000001',
PRIMARY KEY (`PNAME`,`CNAME`,`PID`,`CID`,`OID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
------------------------------------
P always means parent. C always means child. O is order.
My tables/D_TASK/relationships.ini could look like this:
------------------------------------
[D_TASK]
action:label = Child Tasks
action:description = Other tasks which must be completed before this task can be marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.CID
AND R_.PID='$ID'"
[D_TASK]
action:label = Parent Tasks
action:description = Tasks which cannot be completed before this task is marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.PID
AND R_.CID='$ID'"
[D_NOTE]
action:label = Task Notes
action:description = Notes about this particular task.
__sql__ = "
SELECT * FROM R_, D_NOTE
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_NOTE'
AND D_NOTE.ID = R_.CID
AND R_.PID='$ID'"
[D_SUGGEST]
action:label = Suggestions
action:description = Task specific suggestions.
__sql__ = "
SELECT * FROM R_, D_SUGGEST
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_SUGGEST'
AND D_SUGGEST.ID = R_.CID
AND R_.PID='$ID'"
-------------------------------
Yes you saw correct. TWO self relating relationship tabs. Of course that wont work because dataface will read in the first tab, then when it reads in the second, it will override the first. The important thing here is that both work. Thus you can have forward and backward relationships.
Ok...but is there a way to work around this for now? (Why would I ask?) Of course there is. And this is the code in tables/D_TASK/relationships.ini
-------------------------------
[D_TASK]
action:label = Child Tasks
action:description = Other tasks which must be completed before this task can be marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.CID
AND R_.PID='$ID'"
[S_DUMMY]
action:label = Parent Tasks
action:description = Tasks which cannot be completed before this task is marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.PID
AND R_.CID='$ID'"
[D_NOTE]
action:label = Task Notes
action:description = Notes about this particular task.
__sql__ = "
SELECT * FROM R_, D_NOTE
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_NOTE'
AND D_NOTE.ID = R_.CID
AND R_.PID='$ID'"
[D_SUGGEST]
action:label = Suggestions
action:description = Task specific suggestions.
__sql__ = "
SELECT * FROM R_, D_SUGGEST
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_SUGGEST'
AND D_SUGGEST.ID = R_.CID
AND R_.PID='$ID'"
---------------------------------
The S_ is always a system table for me. Dummy is just that, a dummy table. So as not to cause conflicts with either SQL or dataface, it has one field, ID, all specs as listed above. So this works and you get relationships both ways..and tabs that say parent and child (or whatever else you put on the label).
A caveat of course is, your add relationship to this links say...add S_Dummy. Currently I dont know if this can be changed in a dataface ini or not. I imagine it can be changed in smarty or in the delegate classes. I am just getting into these things so I dont have any suggestions for you for that.
But there you go.
I currently have 4 tables of import. R_ (relationships), D_TASK, D_NOTE, D_SUGGEST (D_ means data). Every D_ has a field named ID, primary key, auto increment, mediumint, not null, unsigned, zerofill. R_ looks like this:
-----------------------------------
CREATE TABLE `R_` (
`PNAME` varchar( 10 ) NOT NULL,
`CNAME` varchar( 10 ) NOT NULL,
`PID` mediumint( 8 ) unsigned zerofill NOT NULL,
`CID` mediumint( 8 ) unsigned zerofill NOT NULL,
`OID` mediumint( 8 ) unsigned zerofill NOT NULL default '00000001',
PRIMARY KEY (`PNAME`,`CNAME`,`PID`,`CID`,`OID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
------------------------------------
P always means parent. C always means child. O is order.
My tables/D_TASK/relationships.ini could look like this:
------------------------------------
[D_TASK]
action:label = Child Tasks
action:description = Other tasks which must be completed before this task can be marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.CID
AND R_.PID='$ID'"
[D_TASK]
action:label = Parent Tasks
action:description = Tasks which cannot be completed before this task is marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.PID
AND R_.CID='$ID'"
[D_NOTE]
action:label = Task Notes
action:description = Notes about this particular task.
__sql__ = "
SELECT * FROM R_, D_NOTE
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_NOTE'
AND D_NOTE.ID = R_.CID
AND R_.PID='$ID'"
[D_SUGGEST]
action:label = Suggestions
action:description = Task specific suggestions.
__sql__ = "
SELECT * FROM R_, D_SUGGEST
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_SUGGEST'
AND D_SUGGEST.ID = R_.CID
AND R_.PID='$ID'"
-------------------------------
Yes you saw correct. TWO self relating relationship tabs. Of course that wont work because dataface will read in the first tab, then when it reads in the second, it will override the first. The important thing here is that both work. Thus you can have forward and backward relationships.
Ok...but is there a way to work around this for now? (Why would I ask?) Of course there is. And this is the code in tables/D_TASK/relationships.ini
-------------------------------
[D_TASK]
action:label = Child Tasks
action:description = Other tasks which must be completed before this task can be marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.CID
AND R_.PID='$ID'"
[S_DUMMY]
action:label = Parent Tasks
action:description = Tasks which cannot be completed before this task is marked done.
__sql__ = "
SELECT * FROM R_, D_TASK
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_TASK'
AND D_TASK.ID = R_.PID
AND R_.CID='$ID'"
[D_NOTE]
action:label = Task Notes
action:description = Notes about this particular task.
__sql__ = "
SELECT * FROM R_, D_NOTE
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_NOTE'
AND D_NOTE.ID = R_.CID
AND R_.PID='$ID'"
[D_SUGGEST]
action:label = Suggestions
action:description = Task specific suggestions.
__sql__ = "
SELECT * FROM R_, D_SUGGEST
WHERE R_.PNAME='D_TASK'
AND R_.CNAME='D_SUGGEST'
AND D_SUGGEST.ID = R_.CID
AND R_.PID='$ID'"
---------------------------------
The S_ is always a system table for me. Dummy is just that, a dummy table. So as not to cause conflicts with either SQL or dataface, it has one field, ID, all specs as listed above. So this works and you get relationships both ways..and tabs that say parent and child (or whatever else you put on the label).
A caveat of course is, your add relationship to this links say...add S_Dummy. Currently I dont know if this can be changed in a dataface ini or not. I imagine it can be changed in smarty or in the delegate classes. I am just getting into these things so I dont have any suggestions for you for that.
But there you go.