I am creating a Symfony 1.4 project using Propel 1.5. I would like to know if this can support multiple databases
It seems that the answer is yes: take a look at this page
#config/orgdb.schema.yml
orgdb:
_attributes: {package:lib.model.orgdb} # add this line
organization:
id: ~
Related
So in Rails 4 the long desired feature to use not queries has been added.
Article.where.not(title: 'Rails 3')
Has similar support been added for or queries, or are they planning to make it. I couldn't find anything by browsing through the release notes.
Obviously I tried
Article.where(title: 'Rails 3').or(title: 'Rails 4')
But that does not work.
Article.where(title: ['Rails 3', 'Rails 4'])
is how you'd do that in Active Record.
It's not possible to replicate any arbitrary SQL query using "Rails-y" syntax. But you can always just pass in literal sql.
So you could also do:
Article.where("articles.title = 'Rails 3' OR articles.title = 'Rails 4'")
This now works in Rails 5:
Article.where(title: 'Rails 3').or(Article.where(title: 'Rails 4'))
Code example in Rails's source.
The most common alternative is already answer by #gregates
Recently there has been pull request in rails source
Add #any_of query method to active_record
Which adds or functionality to activerecord
the contributor has already created a gem incase its not accepted
its rails 3.2 and 4 compatible
https://github.com/oelmekki/activerecord_any_of
I havent tried it yet but soon wish to use it looks good to me.
I know that this is an old thread, but anyone else looking for a solution to this problem might find this code helpful:
Article.where(title: ["Rails 3", "Rails 4"])
Maybe that will help you get someone going in the right direction without having to risk sql injection.
It seems that the rails master branch is now supporting OR queries. https://github.com/rails/rails/pull/16052
I assume it will be in the framework with the next major release.
Rails 5 will support it but you can use this backport for Rails 4.2 : https://github.com/Eric-Guo/where-or
Trying to get searching working on Heroku using partial search
The following query generates an SQL error on Heroku, but works correctly in my locally version:
#events.search(params[:search]+":*")
I am using the Heroku shared database service, is this a possible difference in syntax between PostgreSQL versions?
What syntax should I be using to do a partial matching searching against a full-text index in PostgreSQL 8?
Here are the changes in PostgreSQL 9.1.
Perhaps you could try using string interpolation instead of concatenation.
#events.search("#{params[:search]}:*")
I'm not really sure what the kiss emoticon :* adds to texticle's functionality. Maybe I need to learn more SQL.
It turns out that PostgreSQL version 8 does not support partial searches using the :* syntax.
As http://www.postgresql.org/docs/9.0/interactive/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES says, using ":" is for specify prefix matching. E.g. If searching "Australia" with "Aus:" will work but not "ust:*".
So concat OR xxxx LIKE "%yyy%" will works better
You can use the tsearch option with a prefix:
:tsearch => {:prefix => true}
I have a Rails 2 app that uses 2dc_jqgrid and thus squirrel to build jqgrids.
Now looking to move to Rails 3, but I see that squirrel is not coming over.
[ http://robots.thoughtbot.com/post/687890317/the-road-to-rails-3 ]
It seems that squirrel is mainly used for paginate by 2dc_jqgrid.
There are some alternate branches for 2dc_jqgrid - some even labelled rails3 - hopefully one of them will do.
So, any tips/clues on the best way to find the right branch...
Thanks in advance, Chris.
rails3 compatible jqgrid plugins:
https://github.com/doabit/jqgrid-rails3
https://github.com/davebaldwin/jqgrid-rails3 (detailed usage)
https://github.com/springbok/jqgrid-rails3
Looks like this fork might be Rails 3 compatible...
https://github.com/darmou/2dc_jqgrid
I have a Rails app that I'm porting from Rails 1.2 to 2.3. I'm also moving from the Ruby MRI to the latest version of JRuby as well.
In the existing (Rails 1.2) app I use the mysql_bigint plugin to provide support for 64-bit ints as primary keys.
I need to to the same thing for the new application running against a MS SQL 2005 database server.
I'm not sure if the snippet here would help: using UUID as primary key in rails and polymorph relationships
Any ideas where to start?
TIA
Dave
Add this to config/environment.rb:
module JdbcSpec
module MsSQL
def modify_types(tp)
super(tp)
tp[:primary_key] = "bigint NOT NULL IDENTITY(1, 1) PRIMARY KEY"
tp
end
end
end
I am a beginner in Rails. I use 2.3.X.
I just saw Rails 3 is pre-released [edit: now in release candidate!]. I will most probably eventually switch to it.
What are the common coding habits in 2.3 I should not take, so that the switch is as smooth as possible ?
Edit:
I've done my homework and read the Release notes. But they are far from clear for the most crucial points, for example :
1.5 New APIs
Both the router and query interface have seen significant, breaking changes. There is a backwards compatibility layer that is in place and will be supported until the 3.1 release.
This is not comprehensive enough for a beginner like me. What will break ? What could I do already in 2.3.X to avoid having troubles later ?
Looking at my personal coding habits (I have been using Rails since 1.2.x), here's a list of API changes you can anticipate according to Rails 3 release notes.
find(:all)
Avoid the usage of:
Model.find(:all)
Model.find(:first)
Model.find(:last)
in favour of:
Model.all
Model.first
Model.last
Complex queries
Avoid the composition of complex queries in favor of named scopes.
Anticipate Arel
Rails 3 offers a much cleaner approach for dealing with ActiveRecord conditions and options. You can anticipate it creating custom named scopes.
class Model
named_scope :limit, lambda { |value| { :limit => value }}
end
# old way
records = Model.all(:limit => 3)
# new way
records = Model.limit(3).all
# you can also take advantage of lazy evaluation
records = Model.limit(3)
# then in your view
records.each { ... }
When upgrading to Rails 3, simply drop the named scope definition.
Constants
Avoid the usage of the following constants in favour of the corresponding Rails.x methods, already available in Rails 2.x.
RAILS_ROOT in favour of Rails.root,
RAILS_ENV in favour of Rails.env, and
RAILS_DEFAULT_LOGGER in favour of Rails.logger.
Unobtrusive Javascript
Avoid heavy JavaScript helpers in favour of unobtrusive JavaScript.
Gem dependencies
Keep your environment.rb as clean as possible in order to make easier the migration to Bundler. You can also anticipate the migration using Bundler today without Rails 3.
The release notes are the most important thing to keep an eye on. Other than that Jeremy McAnally has some neat blog posts about the whole Rails 3 thing (and has just released a gem to help you with the migration).
I'd say, read the rails release notes and see for yourself what seems the more surprising to you. A lot of stuff changed so reading this is definitively very important.