I'm facing a big problem here. I work using laravel 5.1 and Sql Server 2012. The problem is:
All tables of my database have a trigger that is responsible to log activities on that table. This trigger do a insert after the insert on the main table. This way, every time I insert a new Person, the trigger will insert a new PersonLog.
This way, on Laravel when I do:
$person = Person::create(['personName' => 'Anderson']);
echo $person->id; //it tries to show me the log id instead of person id.
It happens because PDO uses ##identity variable to search for the last inserted id instead of use SCOPE_IDENTITY().
Solutions:
- I tried a pull request on laravel source using a manual query instead of pdo lastInsertId() method. It was denied.
- The another solution is create a class extending PDO and make laravel use my class instead of native pdo. But I don't have any idea of how to do it.
Can you guys help me?
Thank you!
I solved it!
It was really easy by the way, and I can't imagine how I didn't think on it. What did I do? Let me explain:
First, I created a child from SqlServerGrammar inside my project
In my SqlServerGrammar I override the compileInsert method
In my AppServiceProvider on the boot method, I changed the grammar my connection use, this way: \DB::connection()->setQueryGramar(app(App\Classes\MyCustom\SqlServerGrammar::class));
Related
I'm trying to update GroupSettings of individual O365 Group, however I always get error
Resource 'guid' does not exist or one of its queried reference-property objects are not present.
A code I'm using to update the group settings
var graphResult = graphClient.GroupSettings[guid].Request().UpdateAsync(groupSetting).GetAwaiter().GetResult();
I've tried to use Group guid as well as GroupSettings guid, none of that worked.
I can set the settings for the first time (overwrite defaults) using codde below, but update doesn't work afterwards.
graphResult = graphClient.Groups[guid].Settings.Request().AddAsync(groupSetting).GetAwaiter().GetResult();
Any idea what can be wrong please?
Thanks
You should use GroupSettings guid here.
I can repro your issue when I use an incorrect guid here.
You should firstly use GET https://graph.microsoft.com/v1.0/groupSettings to find the GroupSettings guid of the GroupSetting you want to update.
Please note that you should include all the values in the request body even though you don't want to update some of them.
Then you could put it as the guid in your code.
It's stronly recommended to have a quick test in Microsoft Graph Explorer.
Since documentation doesn't say how to update settings for particular group, here it is: you need to use both IDs in call
graphResult = graphClient.Groups[groupGuid].Settings[settingsGuid].Request().UpdateAsync(groupSetting)
In X cart how can we put insert into command.
And also in which specific file?
X-Cart 5 uses Doctrine ORM to work with database records. It adds a few wrapper classes for easier programming, but most of the documentation available for Doctrine applies to X-Cart 5 too.
Also, you can find a great article on adding custom X-Cart 5 database entities here.
You have to create a controller file and create any method and do your logic here like and get this details in tpl file Like getRecords() :
public function getRecords(){
$options = \XLite::getInstance()->getOptions('database_details');
// do your connection login
// do your query logic
}
I'm starting in the big wooly world of Ruby on Rails and i'm trying to get my head around scaffolds and models. (cue, I'm a designer)
I use the rails generate scaffold command
rails generate scaffold Lesson title:string description:text
But is it possible to update the Lesson table with new key, values with rails?
I tried:
rails generate model Lesson title:string description:text dtstart:datetime
But when I run the db:migrate it fails and the only way around I know of to do that is to delete all of the scaffold and regenerate it.
I'm sure there must be an easier solution :)
I think (but im not sure, that it is because of the db/development.sqlite3 file that is not updated, when I delete the content by hand it then run the bd:migrate) is there a way to have evrything updated at once?
I don't think there is a way to do what you describe - generally if you want to add new fields to a model, you want to generate a migration:
rails g migration AddStartToLesson
Then open the migration file and add the code that will add those fields. It will probably end up looking something like this:
class AddStartToLesson < ActiveRecord::Migration
def self.up
add_column :lessons, :start, :datetime
end
def self.down
remove_column :lessons, :start
end
end
And you'll have to update some of the views - probably _form.html.erb, to get the form field to enter that data, and index.html.erb and show.html.erb to display it. (they're probably in app/views/lessons/)
I think you must also update (in rails 5 at least) your lesson_params in lessons_controller.rb in order to allow the new parameters to be passed from the view to the model.
So I have a database table called configs that has the following columns - key and value.
The key looks like so 'core/database/params/username' and the value is 'root'. I want to be able to access this from a Zend_Config object using $config->core->database->params->username. Any ideas how to solve this?
Create your custom class My_Config_Database extending Zend_Config and implement any logic you want ;) Zend_Config_Ini is easy to understand and refactor for your needs ;)
Here is the scenario:
I have a winforms application using NHibernate. When launched, I populate a DataGridView with the results of a NHibernate query. This part works fine. If I update a record in that list and flush the session, the update takes in the database. Upon closing the form after the update, I call a method to retrieve a list of objects to populate the DataGridView again to pick up the change and also get any other changes that may have occurred by somebody else. The problem is that the record that got updated, NHibernate doesn't reflect the change in the list it gives me. When I insert or delete a record, everything works fine. It is just when I update, that I get this behavior. I narrowed it down to NHibernate with their caching mechanism. I cannot figure out a way to make NHibernate retrieve from the database instead of using the cache after an update occurs. I posted on the NHibernate forums, but the suggestions they gave me didn't work. I stated this and nobody replied back. I am not going to state what I have tried in case I didn't do it right. If you answer with something that I tried exactly, I will state it in the comments of your answer.
This is the code that I use to retrieve the list:
public IList<WorkOrder> FindBy(string fromDate, string toDate)
{
IQuery query = _currentSession.CreateQuery("from WorkOrder wo where wo.Date >= ? and wo.Date <= ?");
query.SetParameter(0, fromDate);
query.SetParameter(1, toDate);
return query.List<WorkOrder>();
}
The session is passed to the class when it is constructed. I can post my mapping file also, but I am not sure if there is anything wrong with it, since everything else works. Anybody seen this before? This is the first project that I have used NHibernate, thanks for the help.
After your update, Evict the object from the first level cache.
Session.Update(obj);
Session.Evict(obj);
You may want to commit and/or flush first.
what about refresh? - see 9.2. Loading an object of the docs:
"sess.Save(cat);
sess.Flush(); //force the SQL INSERT
sess.Refresh(cat); //re-read the state (after the trigger executes)
"