21288 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 230 Views |
-
Setting up the correct relation

12 June 2012 at 7:01am Last edited: 12 June 2012 11:08am
I have a basic site for Project tracking. Originally we were just keeping track of what Projects the Developers are working on.
I had a many_many relationship between two DataObjects Project and Developer
Project extends DataObject {
static $many_many = array(
'Developers' => 'Developer'
);Developer extends DataObject {
static $belongs_many_many = array(
'Projects' => 'Project'
);I'm using ModelAdmin (we're just looking to manage it in the backend).
We would like to assign a percentage of the Developer's time when we assign them to a project(s). I haven't been able to come up with a good method to add the PercentTime field into this. Originally I was going to use a checkboxfieldset to pick the developers, but you can't assign the percent of the developers time then. The more I thought about it, there didn't seem to be a good way to enter data on two many_many fields that are related to each other.
Brian
-
Re: Setting up the correct relation

13 June 2012 at 1:28pm
Make a third object for TimeEntry or what have you
Time extends DataObject {
$db = array(
'time' => 'Int'
);$has_one = array(
'dev' => 'Developer',
'pro' => 'Project'
);}
then add a has_many -> time to projects
$has_many = array(
'times' =>'Time'
)You should then be able to assign time in admin.
-
Re: Setting up the correct relation

14 June 2012 at 1:19am
Thanks, that does allow me to assign the time, but I have an odd issue now. I'm adding the Developer and Time with a DataObjectManger (I get the same results with a ComplexTableField) like so:
Project extends DataObject
//Add Developer and Percent of Time
$manager = new DataObjectManager(
$this,
'Developers',
'Developer'
);
$fields->addFieldToTab("Root.Resources", $manager);The Resource Tab that is created Let's me add the Developer and Time, but when I create a new Project, the existing Developer and Time are already entered. I was expecting to see a blank table every time I create a new project
If I change Project to be a Page instead of a DataObject, it works correctly. Reading the documentation on DataObjectManager (and ComplexTableField) the $this states that it's the current Controller. Do I have to use a Page class in order to make this work or is there another way to enter the Developer and Time using a DataObject?
Thanks
-
Re: Setting up the correct relation

14 June 2012 at 3:40pm
Ops sorry I think you'll want many_many not has_many which is what I first said.
Project
$many_many = array(
'times' =>'Time'
)Time
$belongs_many_many
'project' = 'project'
| 230 Views | ||
|
Page:
1
|
Go to Top |


