Foreign Key Mapping
От: Аноним  
Дата: 04.08.11 00:08
Оценка:
Совершенно не понимаю о чем идет речь:


You can't save a collection in the database, so you have to reverse the direction of the reference. Thus, if you have a collection of tracks in the album, you put the foreign key of the album in the track record


Это понятно, если есть таблица Альбом, Треки, альбом на уровне объектов в памяти содержит список треков, то в таблице, Трекс, добавляю ссылку, точнее foreing key на Альбом.
А вот дальше:

The complication occurs when you have an update. Updating implies that tracks can be added to and removed from the collection within an album. How can you tell what alterations to put in the database? Essentially you have three options: (1) delete and insert, (2) add a back pointer, and (3) diff the collection.

With delete and insert you delete all the tracks in the database that link to the album, and then insert all the ones currently on the album. At first glance this sounds pretty appalling, especially if you haven't changed any tracks. But the logic is easy to implement and as such it works pretty well compared to the alternatives. The drawback is that you can only do this if tracks are Dependent Mappings (262), which means they must be owned by the album and can't be referred to outside it.

Adding a back pointer puts a link from the track back to the album, effectively making the association bidirectional. This changes the object model, but now you can handle the update using the simple technique for single-valued fields on the other side.


вы не могли бы своими словами передать о чем тут идет речь?
Re: Foreign Key Mapping
От: saprxm СССР  
Дата: 04.08.11 09:40
Оценка:
А>
А>The complication occurs when you have an update. Updating implies that tracks can be added to and removed from the collection within an album. How can you tell what alterations to put in the database? Essentially you have three options: (1) delete and insert, (2) add a back pointer, and (3) diff the collection.

А>With delete and insert you delete all the tracks in the database that link to the album, and then insert all the ones currently on the album. At first glance this sounds pretty appalling, especially if you haven't changed any tracks. But the logic is easy to implement and as such it works pretty well compared to the alternatives. The drawback is that you can only do this if tracks are Dependent Mappings (262), which means they must be owned by the album and can't be referred to outside it.

А>Adding a back pointer puts a link from the track back to the album, effectively making the association bidirectional. This changes the object model, but now you can handle the update using the simple technique for single-valued fields on the other side.
А>


А>вы не могли бы своими словами передать о чем тут идет речь?


по ходу пьессы, тут речь идёт о расширении обычного foreign key ищё и прямыми ссылками
то есть чтобы не только трэки ссылались на альбом, но и объект альбом имел ссылки на все его трэки

и таким образом ~[дерево получается двусвязным]
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.