Set a column data to another column in same model the rails way - ruby-on-rails-3

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

Related

Xcart - How to delete rows from table in Xcart

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

Can a table field be founded and then updated with a value in mvc Controller

yeah so the question is pretty simple: Can a table field be found using and ID and then updated with a value in mvc Controller?
And before anyone gets downvote crazy... I have no example because I don't know how to do this... it's not a home work question or any other things that you down vote on this site. It's a simple question that I need an answer and a example.
I now you can use the .find to and pass the ID... to a dataset but there is nothing I can find that shows you how to edit the values in the table once you find it.
So this part I get, This will allow me to find the the id with in the dataset.
TEST_DS tEST_DS = db.TEST_DS.Find(id);
if (tEST_DS == null)
{
return HttpNotFound();
}
Also I know that you see a call to the database like This
db.TEST_TABLE.Add(TEST_DS);
I don't see an option for edit or anything like that.
The task is to update a table field, The field is a status field so when the user makes a change on the mvc create form. When they create a record I want to mark a different table's status field with a number that represents a record was created.
Did a search did not see anything.. thanks may be something mvc can't do because of it's limitations or something.
If you do answer question I will need an example of a link to an example on how to do it. Thanks!!
I was able to make this work some I will post It there for others as they might have the same issues when dealing that mvc limitations and such.
So the answer is to simply have your data table in the dbcontext that you need to edit...
The code would not post.. it asking for 4 spaces and I gave it 4 spaces and it did not work so I added a picture.
See CodeAnswer Image

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)

Rails 3 Searching Multiple Models by created_at using sunspot

I'm trying to get a "What's new" section working in my Rails app that takes into account new records created for various tables that don't share any relationships. The one thing they do have in common is that they all have a created_at field, which I'm going to use to determine if they're indeed "new" and then I'm wanting to sort the results by that common field. I tried doing this with Sunspot, but I couldn't figure out how to make use of the the result set returned from the Sunspot search...
For instance in my Uploads and Article models I have:
searchable do
time :created_at
end
and in my search action I'll do this:
#updates = Sunspot.search(Upload,Article) do
with(:created_at).greater_than(1.hour.ago)
end
Which does seem to return something, if I do an #updates.total it returns the number of records I was expecting to find. Beyond this I'm not sure how to actually make use of the records. What I'd like to do is send #updates to a view and determine the model type of each record and then proceed to print out the relevant information, i.e names, descriptions, parent/child record information (for instance upload.user.username).
I might be going at this all wrong, perhaps there's a better option than sunspot for the simple search I'm attempting to perform?
Refer readme for details of how to use the search results. The method you are looking for is "results", which will give you first 30 results, by default:
#updates.results # array of first 30 results