i have this code in executeIndex action:
$pager = new sfPropelPager('News',5);
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(NewsPeer::ID);
$c->addSelectColumn(NewsPeer::TYTUL);
$c->addSelectColumn(NewsPeer::SLUG);
$c->addSelectColumn(NewsPeer::TEKST);
$c->addSelectColumn(NewsPeer::UTW);
$c->addSelectColumn(NewsPeer::WYSWIETLENIA);
$c->addDescendingOrderByColumn(NewsPeer::UTW);
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter("p", 1));
$pager->init();
$this->pager=$pager;
as you can see, im selecting 6 columns from 9column table.
When i want to print UTW column in indexSuccess it print nothing. when i do: print_r($news), im getting this:
[id:protected] => 64
[tytul:protected] => Limit
[slug:protected] => limit
[tekst:protected] => text.....
[pelnytekst:protected] => 2011-12-22 08:54:07
[stan:protected] => 42
[utw:protected] =>
[zmi:protected] =>
[wyswietlenia:protected] =>
and it should be:
[id:protected] => 64
[tytul:protected] => Limit
[slug:protected] => limit
[tekst:protected] => text.....
[pelnytekst:protected] =>
[stan:protected] =>
[utw:protected] => 2011-12-22 08:54:07
[zmi:protected] =>
[wyswietlenia:protected] => 42
So, its ok, when i select columns with same order as in table, but when i skip one, values get messed up. How to fix this?
You need to set the PeerMethod to 'doSelectStmt'.
$pager->setCriteria($c);
$pager->setPeerMethod('doSelectStmt'); // add this
$pager->setPage($this->getRequestParameter("p", 1));
$pager->init();
$this->pager=$pager;
Related
how can I use bulk insert from array in Rails, like below:
name_list = [{"id" => 1,"name" => "bob"},{"id" => 2,"name" => "ted"}]
Namelist.import name_list
I can`t insert values of above array.
You can do that in single insert query using activerecord-import gem.
name_list = [{"id" => 1,"name" => "bob"},{"id" => 2,"name" => "ted"}]
namelist_objects = []
name_list.each do |n|
namelist_objects << Namelist.new(n)
end
Namelist.import(namelist_objects)
The above answers of others will work fine but name_list.size number of insert queries will run which is not feasible when the array is big.
Hope that helps!
You can just pass the array of hash to create
Namelist.create([{id: 1, name: "bob"}, {id: 2, name: "ted"}])
I am not sure what you want, but maybe it will help you. I think you want create Namelist for both name_lists, isn't ?
name_list = [{"id" => 1,"name" => "bob"},{"id" => 2,"name" => "ted"}]
name_list.map{|k| Namelist.create(k) }
I have to use the elastic search for the show the document.
I have written a query like below.
var result = elastic.Search<DocPosts>(s => s.Index(indexname).AllTypes().From(data.from).Size(data.PageSize).Query(q => q.Bool(b => b.Should(sh =>
sh.Match(mt1 => mt1.OnField(f => f.Text).Query(SQuery)) ||
sh.Match(mt2 => mt2.OnField(f => f.Title).Query(SQuery))
))).Highlight(h => h
.OnFields(f => f.OnField(d => d.DocText).PreTags("<mark>").PostTags("</mark>"), f => f.OnField(d => d.Title).PreTags("<mark>").PostTags("</mark>"))
).Filter(f => f.Term(t => t.Id, Id)));
this is working perfectly.
in this, I want to exclude some record that has come in below query.
var Proc = (from p in db.Pro where p.ParId == ParId && (u.UserId != temp.UserId || u.UserId == null)
select p.procID).ToList();
how can I perform this filter or exclude from elastic search?
As you can see the chart displays with yaxis and axis but the value for xaxis is not shown. My data looks like this,
Array
(
[series] => Array
(
[0] => Array
(
[answer_option_group_id] => 0
[name] => All
[data] => Array
(
[999] => 1
[172] => 1
[173] => 0
[174] => 77
[194] => 6
)
)
[174] => Array
(
[answer_option_group_id] => 174
[name] => Does Not Meet
[data] => Array
(
[1459dcb35a7888ab4ff3dd89c07d679e] => 7
[c424759c02fd0900e3ec7c58c745138c] => 1
[e789fa7486d59950d382b8c395de166a] => 2
[b6c632c0a07b9feaa1eefe547a1a6aa8] => 4
[2ecfa0fc3d3990a2ff30009bea9b8ae0] => 2
[b6a52c346ad6a9f4cc58ddfe3c83939e] => 8
[36894aa1fcc16e360813d1ef430bb8fa] => 6
[4284ce3f8523823a457602fe5997fcfa] => 5
[e45e137a7da3e3fe5dc3785d7d628e44] => 11
[fb9bd545acc9397e0c84a8ff5d1a3b92] => 3
[1bcace373da4bb1e821158e3a5fa80a4] => 7
[88928dea322b243c18082e23aa9bc7a4] => 1
[2e9cf454d6eb69e69e744fcc15287f49] => 3
[eaa42f3a7bf5e5f2ac3198d5f8d487a4] => 3
[690463148302dc63a0dfd327ab5253f9] => 1
[325795fe2d5f5a22136b2362ee863be4] => 4
[18bb150bdbf978e058b44ba52d836591] => 1
[418702f6d334d6531e9ac4883a690adb] => 7
[c1ebb58ebb59c5bc6bb87a567c763cfe] => 1
)
)
)
)
I used console.log() to check if I got the data right and the result looked like this,
["All", "Does Not Meet"]
[85, 77]
I tried this on having a jsfiddle and it worked but on my server it didn't. I also dont think this is about the including of scripts since it already displays the chart only that the values are not shown. Any help would be appreciated. Thanks.
I am using rails 2.3. In my application it uses
val = Party.find(:all, :conditions => [" type in ('Physician') || id in (?)",PartyLabel.find(:all,:conditions=>"label_id=#{Label.find_by_label("Can Schedule").id}").collect{|p| p.party_id if Party.find(p.party_id).respond_to?("provider_organizations")}], :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
code to achieve some requirements. Now i wants to split the code in to 2 parts.
1. phys = Physician.find(:all, :include => :provider_organizations, :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
it's working fine.. and the second part will be
2. sch = Party.find(:all, :include => [:as_labels], :conditions => {:label => {:label => "Can Schedule"}}.respond_to?("provider_organizations")).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]}
it shows NoMethodError (undefined method 'provider_organizations' for #<ProviderOrganization:0x1ab81c20>): error message... Any comments could be appreciated..
It looks like respond_to?("provider_organizations") is called for a wrong object. Here is your code #2:
sch = Party.find(
:all,
:include => [:as_labels],
:conditions => {
:label => {
:label => "Can Schedule"
}
}.respond_to?("provider_organizations") # What's this ???
).select{ |physician|
not physician.provider_organizations.blank?
}.collect{ |enum|
[enum.display_name_schedule, enum.id]
}
If I understand it correctly, the respond_to? should be inside the select:
...
).select{ |physician|
physician.respond_to?("provider_organizations") && not physician.provider_organizations.blank?
}.collect{ ...
I've tried a few ways to try to do this but none of them work:
User.where(name:"Jon Sparks").first.purchased_items.where
('(month = 5 AND year = 2012) OR (month = 6 AND year = 2012)')
User.where(name:"Jon Sparks").first.purchased_items.any_of
({:month => 5, :year => 2012}, {:month => 6, :year => 2012})
What I want to do is pull all purchased_items embedded documents in 5/2012 or 6/2012.
Here is your query
User.where(:name => "JohnSparks").first.purchased_items.where(:year => 2012, :month.in => [5,6])