Xcart - How to delete rows from table in Xcart - sql

I am using X-Cart for my project, I need help in how to perform delete query in X-cart. Currently, I am using the below code but it showing me an error.
Can anyone help me in this??
$products = \XLite\Core\Database::getRepo('\XLite\Module\XCExample\FormDemo\Model\NewScroll')->createQueryBuilder('p');
$products->delete('xc_news_scroll p');
$products->getResult();

If you want to remove some object, then you should go:
\XLite\Core\Database::getRepo('\XLite\Module\XCExample\FormDemo\Model\NewScroll')->delete($newScrollObjectToRemove);
If you want to remove some column from the database schema, you need to edit the model class of the entities stored in the table and remove this property there. After that, you will need to re-deploy the store.
Best,
Tony

Related

Django: How do I update only ONE record in my database?

I'm having a lot of trouble trying to update a single (record) object in my database.
context['eval_list'] = Evaluering.objects.update(eval_relationer_id=self.kwargs.get('pk'))
I use objects.update, but it updates ALL my objects fk. How do I achieve only updating one object? I have also tried this:
context['eval_list'] = Evaluering.objects.update_or_create(eval_relationer_id=self.kwargs.get('pk'))
But this creates a new object and does not update the record that I want to update. I know why it creates a new objects, and it is because the FK I'm trying to update is null. Surely, there must be a way to only update and not create a single record? What am I missing here?
I tried adding a filter, but it feels redundant? I tried this:
context['eval_list'] = Evaluering.objects.filter(eval_relationer_id=self.kwargs.get('pk')).update(eval_relationer_id=self.kwargs.get('pk'))
I did consider trying to create an ID of the FK instantly and not later on, but I couldn't really get that to work, but if I created an ID then the update_or_create would work because an ID would exist already, BUT I cannot believe that I can't update a single object without create?
If creating the ID earlier on is the only work around, I will have to figure out how.
MyModel.objects.filter(pk=some_value).update(field1='some value')
The filter gets your object (returns the Queryset with only that object), then the update changes some other field that is not the PK to whatever you want.
In your case probably something like this:
context['eval_list'] = Evaluering.objects.filter(eval_relationer_id=self.kwargs.get('pk')).update(some_attribute='some value')
After help from #Hanny I've figured out was going wrong.
I was trying to filter by the eval_relationer_id, when I should have been filtering by the evaluation pk and getting that specific PK. Otherwise I would be updating ALL the values which is not what I wanted.
So by filtering by pk:
filter(pk=self.kwargs.get('pk'))
And updating by the attribute / fk that I want to update
update(eval_relationer_id=self.kwargs.get('pk'))
This is the end-result:
context['eval_list'] = Evaluering.objects.filter(pk=self.kwargs.get('pk')).update(eval_relationer_id=self.kwargs.get('pk'))

Set a column data to another column in same model the rails way

Is there any shortcut method to set one column data to another in same model?
FYI I do know about for_each method in rails and I can implement that. However what I am trying to ask is if something like User.update_all(last_logged_at: last_sync_position) possible where last_logged_at and last_sync_position are columns of the model user
Also. This is not a migration file I am writing.
I have tried to search for the same but I got an answer in mysql but I am unable to figure out how to convert to rails way of it.
If i understand it correctly you want to update columnt last_logged_at for every User by last_sync_position(every User have its own value). So u duplicate data on model. Im not sure if this is necessery to solve problem that u have but if you found answer in mysql u could use "scope".
Anyway i found this:
Rails 3.x How to write update all based on row value?
that says this
User.update_all("last_logged_at=last_sync_position")
should work

TDBGrid where is the SQL WHERE condition?

I am working on an already started Delphi project where there is a TDBGrid. The grid seems to be filled by a TADOTable that refer to a Bill table in the dataset.
It display a bill by PkBill. I can't seem to find where in the design or in code someone told to load only for this pk.
I need to load multiples Pk at the same time. I'm used to create programmatically a TADOQuery, create a connection, write my SQL code, then do what I want with the result. With those objects/controls, I just don't know where to do that.
Thanks for the help and clarity!
Check TADOTable.MasterSource to see if it's in the Master-Detail relationship.
Or you could check TADOTable.Filtered and TADOTable.Filter to see if it's being filtered by PkBill.

Table structure for Messages System

Hi i need to design a messaging system like facebook. I was thinking to build table similar
(source: serviciipeweb.ro)
where i can store olderMessage in another table so i can make quicker query in Message Main table...
but i cant resolve the problem about deleting messaging. If a user delete a message the other one should still read it.
How can i build it?
I googled but i didnt find anything.
P.S: I must use SQL-SERVER
Thanks
Create two fields in your Message table:
DeletedByFrom
DeletedByTo
Filter your results on this:
where DeletedByFrom = False
So you only get the rows that weren't deleted (in this case by the 'From' user)

Fetching data from multiple tables in yii

I have 2 tables
AutoScriptArgumentClass
id
ScriptArgumentClass
AutoTestScriptMeta
id
AutoTestScript_id
ScriptArgumentClass_id
here is my query.
select sac.id,sac.ScriptArgumentClassType
from AutoScriptArgumentClass sac,AutoTestScriptMeta tsm
where tsm.ScriptArgumentClass_id = sac.id
and tsm.AutoTestScript_id=129
how do I write this in yii
I would like to have in this manner:
**$data=AutoTestScript::model()->findAll('Category_id=:parent_id',
array(':parent_id'=>(int) $_POST['TestCaseCategory']));**
$data=CHtml::listData($data,'id','ScriptName');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
Thanks
I am afraid this will not be possible, as you are trying to get the data from multiple table into an instance of a CActiveRecordModel of a particular table.
This model does not have the instances of the columns of the other table, hence it cannot not avail them to you.
Thanks.
Its possible in two condition. first you write a function in in your controller which contain the proper query and call the function from cgrid view or you can check the page more efficient way
http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/
make sure the tables maintain the reletaionship. if your tables are in MYISAM format change it into INODB and try.. hope its works for you