I need a model to fetch and save to different sources.
The fetch would be a view, that requires a constraint in the where clause. The save would be to a table that matches the views returned schema exactly.
To give some background, we have some tables containing indirect content as part of a localisation system.
Item : title - content1 descrption - content2
content: content1 = 'Great item', languageId = 1 content2= 'great description' , languageId = 1
Currently we fetch a models data, and after the fetch, we run queries to obtain the indirect content, in the active language, and swap the id's on the models localised fields with the resolved content. When we save, we do something similar, and parse out the content of the indirect fields, save them in the content table, replace these fields on the model with the content id's.
Works great, however, it is not performant.
So I would like to instead obtain the record from a view, which has already joined the content table, or hydrate the record via a custom query which would deal with the join (possibly better as more dynamic).
Then I need to save the model to its original table, not the view.
Problems :
- I need pass a constraint - languageId - to the where clause of the source view. Where is the correct place to do this?
- I need to switch the table source (getSource) of instantiated models, I would rather not invalidate the meta data cache as this is potentially another performance issue. Is there a way to do this?
Thanks for any feedback / advice.