Suppose i have inserted two rows ( id: 1, attribute_id: 1 ) , ( id: 2, attribute_id: 2) in the `relationship_attribute` table
next i want to insert the attribute values associated with these two id's : 1 and 2 in the table `relationship_attribute_text_value table`
> ( id: 1, attribute_id: 1 ) , ( id: 2, attribute_id: 2) sorry i meant attribute_type here not attribute_id
monkey
akashgp09: We'll need some utility functions to update the relationship_attribute_set elements, like we do for other sets. Have a look for example at https://github.com/bookbrainz/bookbrainz-data-j... , as well as this file with some set-realted utility functions:
So I'm not sure I understand specifically what the question is. Where are you blocked?
BrainzGit joined the channel
akashgp09
after inserting some rows in the `relationship_attribute` table how will i insert the attribute values associated with this rows (id) in the table `relationship_attribute_text_value`
monkey
Something like `new RelationshipAttributeTextValue({id: myRelAttributeId, value: "Hello!"}).save()` ?
`new RelationshipAttributeTextValue({id: myRelAttributeId, value: "Hello!"}).save(null, {method: 'insert'});` to be more exact
akashgp09
ye, how can i insert multiple rows at once ?
monkey
I guess I would call the method twice. Not sure if there's an option for saving multiple new rows
Let me look
No great options it seems. I would recommend calling `await new RelationshipAttributeTextValue(…).save(…)` twice, or use the underlying knex library if for some reason that doesn't work (see https://github.com/bookshelf/bookshelf/issues/445)
akashgp09
yeah thanks for this : )
monkey
👍
akashgp09
actually the problem is something bigger. give me some time I will write this up and explain the issue properly . Right now what i can think of is that it's not appropriate to add foreign on `relationship_atrribute` table id column
instead we should have the text_value column in the same table `relationship_atrribute` table
also no other table `relationship` , `aliases' , `release_event`, `identifiers` have foreign key on their `id` column
`attribute.map(row => await new RelationshipAttributeTextValue({id: row.id value: 'someValue' }).save(null, {method: 'insert'}));` looks pretty good to me at first glance.
The textvalue id ends up equal to the attribute id, so we should be able to do an SQL JOIN on that id.
When the value changes, we also create a new attribute row and a new attributeSet row.
The issue with putting the text value in the relationship_attribute table is that an attribute's value will not always be text, for example for dates.
Now we do need to make sure that we can retrieve the value easily, say with `Relationship.forge(…).fetch({withRelated: attributeSet.attribute.value})`.
akashgp09
> The textvalue id ends up equal to the attribute id, so we should be able to do an SQL JOIN on that id.
the joining part is OK
but i am conern with how will we know which attribute id will have which textValue
one more thing
monkey
Ah, I see maybe where the misunderstanding is: the relationship_attribute_text_value has no column `id` but instead the column is `attribute_id` with a foreign key pointing to an attribute
await new RelationshipAttributeTextValue({id: row.id value: 'someValue' }).save(null, {method: 'insert'})) will this always be a insert method ?
monkey
So when we join, we join on the attribute_id
I think we'll only ever insert new items (if the value is new or if the value changes)
That's how we keep the history of modifications
Whenever an attribute value changes, we create a new attribute (we keep the attributes that haven't changed as-is ), put them all in a new attributeSet and create a new relationship with that new attributeSet, and finally a new relationshipSet with the new relationship (and any previous rels that have not changed)
It's a bit involved but I don't see another solution if we want to keep revision history like we do with the rest of the sets