Mjoin with fields on linking table?

Mjoin with fields on linking table?

kicks66kicks66 Posts: 11Questions: 6Answers: 0

I have a structure whereby I use a linking table to link creators to lists. I also record a "note" on those links, e.g.:

creators_to_list:
user_id | list_id | notes

in datatables I am using:

->join(
Mjoin::inst('creatorLists')
->link('creators.id', 'creators_to_list.user_id')
->link('creatorLists.id', 'creators_to_list.list_id')
->fields(
Field::inst('id')
->options( Options::inst()
->table( 'creatorLists' )
->value( 'id' )
->label( 'list_name' )
),
Field::inst('list_name'),
Field::inst( 'creators_to_list.notes' )
)
)

which returns the data correctly. however on my frontend with Editor I have:

Datatable.Editor({
fields: [{
label: 'Notes',
name: 'creatorLists[0].creators_to_list.notes'
}]
})

yet when i make changes on my frontend they post through like this (and hence fail)

data[row_9690][creatorLists]: tester
action: edit

i.e. they are posting as creatorLists fields, not creator_to_list fields

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Unfortunately, at the moment the linking table is that and that alone - a linking table. It doesn't support other columns, and indeed, if you edit a row with an Mjoin, it will delete other fields in the link table, so it is actually quite important that you don't use other columns (data loss).

    There was a discussion on this topic a little while ago (which I can't immediately find - apologies), and this is something I plan to address in future with the Editor server-side libraries (probably through a primary key on the linking table), but at the moment - sorry, that isn't possible.

    Allan

  • kicks66kicks66 Posts: 11Questions: 6Answers: 0

    Hey Allan - thanks for your swift reply! In the meantime, is it possible to handle this seperately? i.e. can I just intercept the request (on frontend or backend) and handle it myself?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The update? Yes, at the server-side check for the action parameter being submitted as edit. If that is found to be true, don't get the Editor libraries to handle the request, do so yourself. The client / server data interchange used by Editor is documented here and I'm happy to answer any questions you might have about it.

    Allan

  • kicks66kicks66 Posts: 11Questions: 6Answers: 0

    I guess the issue here though is that its not sending the data from the frontend correctly - its sending creatorLists but not the data from the creatorLists[0].creators_to_list.notes field - so how would i get that to work?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes, that's a good point. It is sending it correctly, but only for the binary state that it is expecting. Anything more complex is going to need a custom field type I'm afraid.

    Might nested editing like in this example be an option for you?

    Allan

Sign In or Register to comment.