Hi,
I'm writing an open source app, something similar to Trac. I have a
slightly different approach to bug tracking - dynamic "ticket
attributes" - instead of having a few fixed attribs (ticket priority,
severity, component, milestone, etc.), project's owner creates them by
himself. For example, in his project every ticket may have an
associated city, color or priority.
I'm not sure how to accomplish model associations properly, so here I
am.
My models (only those related to the issue):
* Project (that's another difference - Trac doesn't handle multiple
projects and that's basically why I'm doing this), hasMany Ticket and
Attribute
* Ticket
* Attiribute (for example "city", "color", "priority"), hasMany
AttributeValue
* AttributeValue ("London", "Manchester", etc.)
The problem is that "City" is not a hard-coded model, but a one of
values of Attribute model. This is the solution I'm thinking of:
* In TicketsController::beforeFilter() I'm loading a Project with
associated models. $project = $this->Ticket->Project->read($id); It
contains all attributes. Then I'm doing $this->Ticket->bind for every
existing Attribute that this project has. Something like this (typing
it right now, probably has errors):
foreach($project['Attribute'] as $attr) {
$this->Ticket->bindModel(
array('hasAndBelongsToMany' => array(
$attr['name'] => array( // of course I'd have to
validate attribute
names to make sure they are valid key names (but that's irrelevant
now).
'className' => 'AttributeValue',
'joinTable' => 'tickets_attribute_values',
'foreignKey' => 'ticket_id',
'associationForeignKey' => 'attribute_value_id',
'unique' => true,
'conditions' =>
array($attr['name']'.attribute_id' => $attr
['id']),
)
)
);
}
Does that sound reasonable? Is it how it should be done? If not, how
should I do it so that other Cake kids won't laugh at me?
My needs are pretty standard: I'm gonna want to paginate through
tickets, create filters ("only tickets from London and Manchester"),
create and edit tickets. I've already coded all of this, but with
fixed models (Priority, Severity, etc.).
cheers,
muszek - Mateusz Mucha
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---