Hello everybody, i'm facing a big problem and i'm wondering if any of you has spended some time on the same issue, so we can share some knowledge. I'm building an application on an already existing database with a lot of n:m relations and with junction tables made of 2 fields - the foreign keys of the two tables involved in the relation. In junction tables there are NO id fields, and primary keys are defined as both the fields in the tables. AFAIK, handling such associations in Akelos requires the presence of a separate primary key, but i can't add such field to all tables in the database (and, as a more general consideration - it is a common design habit to build minimal junction table without a basically useless separate primary key). I'm analizing Akelos core function attempting to add the capability to manage multiple primary keys in habtm associations, but i'm pretty new to Akelos and to MVC pattern in general. Is there anybody having the same problem? Hints from Akelos/ Rails gurus? :-)
I too think this is a wrong implementation. Right now, the seperate id-column is only used in the delete()-method. line 431..
...->findAllBy($options['foreign_key'].' AND '.$options['association_foreign_key'], $this->Owner->getId(), $id))
returns ActiveRecords obviously, we then destroy one-by-one.
what's the reason we don't use delete/deleteAll here? destroy means: notify observers, but the join table shouldn't have observers.
This could be a cheap solution:
foreach (array_keys($Associated) as $k) { $items_to_remove_from_collection[] = $Associated[$k]->getId(); }
$this->JoinObject->setPrimaryKey($options['join_class_primary_key']);
if($this->Owner->getId()) $this->JoinObject->deleteAll($options['foreign_key'].' = '.$this->Owner->getId());
instead of foreach cycle of line 448 - 465 in AkHasAndBelongsToMany.php
1 to 3 of 3