Relational delete constrain custom message yii2? - yii2

Delete button not working for relational data in yii2. Because its has child data. Now i want to show custom message.enter image description here

If the deletion is throwing an exception you can catch it and add an error to the model by using addError function

Related

On click of a checkbox of matching GUID from table row, How to highlight exact GUID Modal member

Problem Statement :
We have a table of rows with unique GUID's and also Revit 3D Modal members associated with GUID's.
I am trying to highlight exact GUID Modal member On click of a checkbox of matching GUID from table row.
Please suggest on triggering point to highlight modal member dynamically.
Please find the attached screenshot for the reference.screenshot
There are a couple of ways of finding the object with your GUID. I would recommend using the Model.getExternalIdMapping method. It will generate a dictionary mapping internal IDs ("dbIDs") to external IDs (in this case, Revit GUIDs). You can then use this map in an "inverted" way, finding a dbID for a specific GUID.
Once you know the dbID of your object inside the viewer, you can use viewer.select, viewer.isolate, or similar methods to provide visual indication.

How to get record's primary key value on saving in manual mode?

I have a model in manual save mode and a form in create mode. Once I add details and click on submit it should create the record and
alert something like 'Your request is registered with id=7' where id is the id (primary key).
Note the primary key is in auto increment and generated dynamically.
In manual save mode I am using saveChanges to save the record but seeing error:
SEVERE: Record RecordKey{key=private$2, model
key=1ymdoCYoHKEGpumlXveKKZh_57jUjd9OY|7LyXBUY46K9Jl6GRCy1DeL32kXmnGHis}
already deleted.Failed: getProperty at Object.
(UserCreationRequest:12:37) at createUCR (UserCreationRequest:11:19)
at
UserCreationRequest.Container.UserCreationRequestPanel.UserCreationRequestPanelFooter.UserCreationRequestPanelSubmitButton.onClick:1:1
(In error 12:37 points to record._key)
Code: (executed OnClick of submit button)
widget.datasource.saveChanges(function(record) {
alert('Your request is registered with id='+record._key);
}
Can someone please advise how to get the primary key on saving in manual mode?
Additional Info Reference:
The above code has worked for me in some other place for some other model. But not working for the current model, is it because the current model has a relation?
I added a new datasource in the Datasources section of the current model
and by using that its working fine. But why is not working fine with the original one?
Also FYI, this is a similar issue but it did not help as it's a different approach. I'm keen to save using the widget itself.
First, we need to understand that the create mode is not the same as the normal mode. Having that clear, we can do the following:
Assuming the datasource name is MYDATASOURCE, the form datasource should be MYDATASOURCE(create). Then, on the onClick event of the submit button widget inside the insert form, use this:
widget.datasource.createItem(function(record){
app.datasources.MYDATASOURCE.saveChanges(function(){
console.log(record._key);
});
});

How to avoid triggering unique validator on model edition?

I'm using Flask, SQLAlchemy and WTForms. I have a number of properties in my model object which are marked as unique and nullable=False. This works fine when creating a new row in the database but when I try to edit an existing object the validator on WTForms fails with
{'aproperty': [u'Already exists.']}
How can I make this validation pass without having to change my data model?
Update
Following the documentation was of no use to me.
You need to associate the existing record with the form. Otherwise the validator has no way of knowing that you're updating an existing record instead of creating a new one. Something like the following should do the trick:
current_obj = ...
form = MyForm(request.form, obj=current_obj)
form.validate_on_submit():
form.populate_obj(current_obj)

Does calling ToArray on IQueryable de-attach the entity in LinqToSql?

I have a LinqToSql query that returns an array of Article objects like so:
return db.Articles.ToArray();
I then loop over this array and start to delete some items that meet a certain criteria, for simplicity let's say I delete them all, like so:
foreach (var item in array)
db.articles.DeleteOnSubmit(item);
The call to DeleteOnSubmit(entity) throws an invalid operation exception, it's message says "Can not delete an entity that has not been attached". I modified the code to get the entity first then delete it and it worked just fine. Here's the working code:
db.DeleteOnSubmit(db.Articles.Where(c=>c.Id == item.Id))
Now, I know it would work if I modified the repository to return IQueryable instead of a native array, I just don't understand why? Does ToArray has anything to do with this invalid operation exception?
Thanks.
ps: db is a reference to a DataContext object.
I suspect your using different DataContexts when selecting entities and when submitting changes. If this is the case, the error is natural and would still happen if you returned an IQueryable instead of a native array. Either you Attach an entity to the new data context or you use the same where you selected the initial entities.
Can you put it all in one method and try?
The answer is "No", it doesn't.
Unless you are using differen't db for delete than select (could happenw ithout you realize it) or db.ObjectTrackingEnabled is set to false somewhere.

LinkDataSource can't load DataContext

I am trying to populate a dropdown list control on an web page using VS 2008 and keep getting an error that it can't load the DataContext. My backend is a SQLx server 2005 DB. I create a Link To SQL data context and have 1 table in it. My LinKDataSource is as follows -
asp:LinqDataSource ID="LinqDataSource1" runat="server"ContextTypeName="DACDataContext" TableName="portfolio">
/asp:LinqDataSource
My dropdown definition is:
asp:DropDownList ID="ddlPortfolio" runat="server" Width="165px" DataSourceid="LinqDataSource1" DataTextField="porfolio_name"
DataValueField="portfolio_id">
/asp:DropDownList
I can see in my properties of my DatContext that the ContextTypeName is DACDataContext
The pecific errors I get are:
HttpException (0x80004005): Could not load type 'DACDataContext'.
and
InvalidOperationException: Could not find the type specified in the ContextTypeName property of LinqDataSource 'LinqDataSource1'.]
I know this must be something really stupid but I am at my wits end.
Please help.
Verify that DACDataContext is public and you may also try fully qualifying the type (ie. ContextTypeName="MyNamespace.DACDataContext")