sql,ruby-on-rails-3,postgresql,activerecord,arelRelated issues-Collection of common programming errors
OrangeWombat
sql hibernate
We are having an issue in some Hibernate mappings. The setup below worked previously with Hibernate 4.1.3, but now fails in Hibernate 4.2.3. The failure is “org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions() – Invalid column name ‘position’.”The basic structure we have is meant to collect employee survey responses. We have a primary table for EmployeeResponse, which then has a one-to-many relationship with Responses. Each record in Responses is a response to a particular survey ite
user2355051
php mysql sql phpmyadmin server2go
The environment this is running in is as follows. It’s an instance of Server2Go on a thumb drive.Apache/2.2.15 (Win32), PHP/5.3.2, SQLite 2, MySQL 5.1.46-community,and Perl 5.8.The php script opens a file and loops through it line by line. A query is built and executed with the information in each line of the file. The table structure is as follows:CREATE TABLE `exp_report` (`b_unit` varchar(11) DEFAULT NULL, //IMPORTANT TO THIS PROBLEM`b_unit_title` varchar(255) DEFAULT NULL,`act_
Stagleton
android sql
I’m trying to modify an SQL table to have true false values. I am using type BIT for a 1 or 0. I tried to alter the table but it does not seems to be working properly. The column index is -1. For my sqlitehelper class, I tried using this for my onupgrade method:@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {Log.d(TAG,”inner onupgrade called”);Log.w(TAG, “Upgrading database from version ” + oldVersion + ” to “+ newVersion + “, which will destroy all old data”);
AKX
php mysql sql sql-injection
Keep in mind please that I am learning still. I am working on a website and I am simply adjusting and copying codes for the most part, from the existing ones, because that’s the easiest way for me to understand them.I keep getting an sql error that is caused by the use of apostrophes, and I’ve started putting in the mysql_real_escape_string() for every text field, which solved the individual problems.Now this is genuinely just me asking for help. Please don’t be sarcastic, I am really just tryin
Mike Causer
php sql sql-server pdo
I am trying to create a simple PHP page that describes the tables of my DB so I can always find a table/column name or data type that I am looking for (a sort of poor man’s schema if you will).I have done this in the past with a Sybase DB but our new DB will be SQL Server so I am trying to reproduce it using that DB.try {$conn = new PDO(“odbc:Driver={SQL Native Client};Server=servername,1433;Database=dbname;Uid=user;Pwd=password;”);$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTIO
Paul
sql stored-procedures request binary-data plaintext
There are several SQL servers having stored procedures, for example Microsoft SQL Server or PostgreSQL. There are also several client side objects implementing stored procedures calls (TADOStoredProc in Delphi, SqlCommand in .NET Framework etc.).The question I always wanted to ask is:are stored procedures executed always in special efficient way with binary representation of their parameters or are the super-advanced objects which represent stored procedures’ parameters always converted to a pla
user2428118
java sql jdbc derby
Please have a look at the following code. I am using Apache Derby as an embedded databasepublic List getDetails(String name){List details = new ArrayList();name = name.replaceAll(“\\s+”, “”).toUpperCase();try{createConnection();PreparedStatement ps = con.prepareStatement(“select * from PhoneData where upper(rtrim(NULLIF(names,”))) + upper(rtrim(NULLIF(middleName,”))) + upper(rtrim(NULLIF(lastName,”)))=?”);ps.setString(1, name);ResultSet rs = ps.executeQuery();// System.out.println(“First Mob
patel the rock
sql database db2 datastage cognos-10
I’m running a data stage job, Input through DB2 and output to DB2. Input side has a query containing joins and functions.I’m getting the following warning message;TRN_HEALTH_INSURANCE_DETAIL, 2: STATEMENT INSERT INTO HEALTH_INSURANCE_DETAIL (RISK_DETAIL_ID,RISK_COVER_ID,RD_POLICY_SYSTEM_NO,RD_POLICY_END_NO_IDX,RD_POLICY_ID,RD_LEVEL1_ID,RD_SUM_INSURED_AMT_LC,RD_PREMIUM_AMT_LC,PREMIUM_AMOUNT_FC,SUM_INSURED_AMT_FC,RD_REC_TYPE,RD_EFFECT_FROM_DT,RD_EFFECT_TO_DT,RD_END_EFFECT_FROM_DT,SEX_MAS_CD,MARIT
Svetlin Zarev
java mysql sql jpa
I am trying to create the query with join in multiple tables and passing lists as parameters. I am putting the null & empty check within the query string. However i am getting NullPointerException on QueryNode.getDataType. Below are the query and the exception.query = em.createQuery(“select avg(kpi.duration), kpi.taskId from KPI kpi, User user, UserRole userRole, Shop shop where ” +”(user.clientId = :customer or :customer is null) and (kpi.userId in :users or :users is null or :users = ” )
forhas
sql spring log4j
I added a DB appender to my log4j.properties file:log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender log4j.appender.DB.URL=jdbc:mysql://${db.url}/mydb log4j.appender.DB.driver=com.mysql.jdbc.Driver log4j.appender.DB.user=user log4j.appender.DB.password=password log4j.appender.DB.sql=INSERT INTO logs (Date, Logger, Priority, Message) VALUES (‘%d’, ‘%c’, ‘%p’, ‘%m’) log4j.appender.DB.layout=org.apache.log4j.PatternLayout log4j.appender.DB.threshold=INFOThis is how my table looks like:CREATE TABL
Ringo Blancke
ruby-on-rails-3 postgresql bundler pg
I’m on Mac OS X 10.8.2. I install Ruby+RVM using the RailsInstaller, so I am currently on ruby-1.9.3-p194. My application uses Rails 3.2.11.When I run bundle install, here’s the error I see:Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension./usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb –with-pg-config=/usr/bin/pg_config Using config values from /usr/bin/pg_config checking for libpq-fe.h… yes checking for libpq/libpq-fs.h… yes checking for pg_config_
dda
mysql ruby ruby-on-rails-3 xampp mysql2
I’m stuck trying to figure out how to get OS X Lion with a XAMPP installation’s MySQL to work with the mysql2 gem in rails.Here’s what I’ve tried:Installed the XAMPP Dev Kit Installed mysql5-server with both port and brew. Both of which I’ve now uninstalled. As it didn’t fix the problem. Installed mysql5 community edition from DMG file. Now uninstalled as it didn’t fix the problem. Downloaded 32-bit version of mysql5 community edition as a tar. Extracted folder to ‘/var/mysql’Here’s the command
yper
ruby-on-rails-3 imagemagick openmp vps unicorn
Sitting here with a simple rails 3 app in which I have a simple Gallery model and each gallery has many images. The image model is extended with paperclip and with the following optionshas_attached_file :local, :styles => {:large => “800×800>”, :medium => “300×300>”, :thumb => “100×100#”, :small => “60×60#”}In my galleries_controller I have the following action that is implemented in order to work with the jQuery-File-Upload plugin. thereby the json response. def add_imagega
jaycode
ruby-on-rails-3 bundler mysql2
in my mac OSX 10.6 32 bit, I can install mysql2 gem quite easily, but not in mini mac 10.6 64bit server.I have installed MySQL 5.5.11 in troublesome server, while in my home mac MySQL 5.5.0.m2 Somehow when I run bundle install, in server it tries to install mysql2.0.3.2 while in home mysql2.0.2.6Please don’t tell me toenv ARCHFLAGS=”-arch x86_64″ sudo gem install mysql2 –version ‘= 0.2.6’ — –with-mysql-config=/usr/local/mysql/bin/mysql_configI tried that, doesn’t work.Included /usr/local/mysq
Jseb
ruby-on-rails ruby ruby-on-rails-3 imagemagick rmagick
I am trying to install ImageMagick on Windows. What I did is install Windows RailsInstaller created my version and now I need to use ImageMagick but for some reason it doesn’t work.I took the binary source code and install and run it from this page but didn’t seem to do the trick http://www.imagemagick.org/script/binary-releases.php#windowsI also try the following http://www.youtube.com/watch?v=gEWAVlNCKhg but it doesn’t workFor the first example In cmd all I have to do is the following command
rossta
ruby-on-rails ruby-on-rails-3 gem homebrew mysql2
ok, feel super dumb about asking a question that’s apparently been asked multiple times. apologies in advance. am following this tutorial: http://squarism.com/2011/04/01/how-to-write-a-ruby-rails-3-rest-api/it requires mysql2 … tried to install it via “gem install mysql2″this is what i get: Building native extensions. This could take a while… ERROR: Error installing mysql2: ERROR: Failed to build gem native extension./Users/name_withheld/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb chec
Romeo M.
ruby-on-rails-3 rvm
I managed to install it locally without any problem but on my VPN I can’t follow the guide at all. Execution stops at gem install rails -v 3.2.3 with an error that I can’t seem to fix after googling for hours.gem install rails -v 3.2.3 ======================================== Fetching: i18n-0.6.0.gem (100%) Fetching: multi_json-1.3.6.gem (100%) Fetching: activesupport-3.2.3.gem (100%) Fetching: builder-3.0.0.gem (100%) Fetching: activemodel-3.2.3.gem (100%) Fetching: rack-1.4.1.gem (100%) Fetchi
?????? ???????
ruby-on-rails ruby-on-rails-3 rubygems libxml-ruby
I tried install libxml-ruby v2.3.3 for Mac OS X.localhost:tmp$ uname -a Darwin 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:26:45 PDT 2012; root:xnu-1699.32.7~1/RELEASE_I386 i386localhost:tmp$ ruby -v ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.4.2]localhost:tmp$ gem -v 1.8.24gem install libxml-ruby -v ‘2.3.3’ Building native extensions. This could take a while… ERROR: Error installing libxml-ruby: ERROR: Failed to build gem native extension./Users/ruslan/.rvm/rubies/ru
Ross
ruby-on-rails-3 rubygems bundler railstutorial.org
I’m following the Michael Hartl Ruby on Rails Tutorial & there is a part where he is he he instructs you to update your Gemfile to include:group :production dogem ‘pg’, ‘0.12.2’ endAnd then enter the below commands in your terminal:bundle update bundle install –without productionWhen you run the bundle update command it throws back the below errors.sample_app:$ bundle update Fetching gem metadata from https://rubygems.org/……… Fetching gem metadata from https://rubygems.org/.. Resolvin
robertwbradford
ruby-on-rails-3 make gem bundle
I’m getting the following when running “$ bundle” after adding “gem ‘redcarpet'” to Gemfile:$ bundle … Using paperclip (2.3.11) Using passenger (3.0.7) Installing redcarpet (1.17.2) with native extensions /Users/robs/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)/Users/robs/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb creating Makefi
ted.strauss
postgresql windows-7 nsis
I am building a Windows 7 installer with NSIS for internal company use. One step in the install is to backup a Postgres DB using pg_dump.exe, then restore a file packaged in the installed usign pg_restore.exe. These two executables are normal helper tools include with any Postgres installation, so they can be expected to exist on the user’s machine. I want to execute this operation like so:ExecWait ‘C:\path\to\file\pg_dump.exe –host localhost –port 5432 –username “postgres” –no-password —
Gus Shortz
ruby osx postgresql gem homebrew
I have been trying to install the Ruby PG gem, but kept getting the “Failed to build gem native extension.” error.After sifting through a lot of google results, I tried nearly every recommendation I came across, all without luck. However, I believe I’ve tracked down the source of the problem … Homebrew.Homebrew installed PostgreSQL 9.0.4, but only with the 32-bit libraries. As I am running Snow Leopard (10.6.8) with XCode 3.26, I need the 64-bit libraries in order to compile everything without
javshak
java postgresql rmi database-performance
I have a performance issue where the application cannot execute a DB query when a particular page is accessed and the page fails to load. The stack trace for the error is as follows: Caused by: java.rmi.UnmarshalException: Error unmarshaling return; nested exception is: java.lang.ClassNotFoundException: org.postgresql.util.PSQLException (no security manager: RMI class loader disabled) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:246) at sun.rmi.server.UnicastRef.invok
Ringo Blancke
ruby-on-rails-3 postgresql bundler pg
I’m on Mac OS X 10.8.2. I install Ruby+RVM using the RailsInstaller, so I am currently on ruby-1.9.3-p194. My application uses Rails 3.2.11.When I run bundle install, here’s the error I see:Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension./usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb –with-pg-config=/usr/bin/pg_config Using config values from /usr/bin/pg_config checking for libpq-fe.h… yes checking for libpq/libpq-fs.h… yes checking for pg_config_
Tony
ruby-on-rails postgresql installation gem bundler
I’ve installed the pg gem as shown, but…Building native extensions. This could take a while…Successfully installed pg-0.11.0ERROR: Could not find a valid gem ‘-‘ (>= 0) in any repositoryERROR: Could not find a valid gem ‘-with-pg-config=/usr/local/pg/bin/pg_config’ (>= 0) in any repository1 gem installedInstalling ri documentation for pg-0.11.0…Installing RDoc documentation for pg-0.11.0…Something strange happens when I bundle install and it won’t completely install the pg gem:F
jribeiro
postgresql node.js upsert pg
I’m trying to do an insert or update in a postgres database using node.js with pg extension (version 0.5.4).So far I have this code: (…)client.query({text: “update users set is_active = 0, ip = $1 where id=$2”,values: [ip,id]}, function(u_err, u_result){debug(socket_id,”update query result: “,u_result);debug(socket_id,”update query error: “,u_err);date_now = new Date();var month = date_now.getMonth() + 1;if(!u_err){client.query({text: ‘insert into users (id,first_name,last_name,is_active,ip,da
Stephan
postgresql sonar
I’ve tried to upgrade Sonar 3.5.1 to the latest version SonarQube 4.0. I did all the recommended upgrade steps and updated the new configuration files with proper values from the older versions.For some reason, when I switch to a external postgres database (disabling the embedded H2) which holds our data, I always get a JNPE2013.12.19 13:43:27 ERROR o.s.s.p.PlatformLifecycleListener Fail to start server java.lang.NullPointerException: nullat org.sonar.server.db.EmbeddedDatabaseFactory.start(Emb
stewartmccoy
ruby-on-rails postgresql gem pg
I’m working on building the twitter clone app in Hartl’s Rails Tutorial. I cloned my git repo (https://github.com/stewartmccoy/rails_tutorial) and put code on to my personal computer, which had previously been on my work computer. So, my developer environment might be slightly different than what’s specified in my Gemfile. My environment: Mac OS 10.6.8 Rails 3.2.13 ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]* LOCAL GEMS *actionmailer (3.2.13, 3.2.11, 3.2.1) actionpack (3.2.1
Nirav Shah
ruby-on-rails postgresql heroku rails-postgresql
I did a bundle update. Now, I am trying to push my app to Heroku and it is not working:Here is the error that I am getting:Installing pg (0.12.1) with native extensions /usr/ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)/usr/ruby1.8.7/bin/ruby extconf.rb checking for pg_config… yesUsing config values from /usr/bin/pg_configchecking for libpq-fe.h… yeschecking for libpq/libpq-
Jorge Infante Osorio
postgresql wso2
I configured the GReg 4.5.0 to use an external DB in postgresql. When I run wso2server.bat -Dsetup I see this error:TID: [-1234] [WSO2 Governance Registry] [2012-10-17 23:35:38,514] ERROR {org.wso2.carbon.humantask.core.HumanTaskServer} – Humantask Database Initialization failed. {org.wso2.carbon.humantask.core.HumanTaskServer}TID: [-1234] [WSO2 Governance Registry] [2012-10-17 23:35:38,527] ERROR {org.wso2.carbon.humantask.core.internal.HumanTaskServiceComponent} – Failed to activate the Huma
wantrapreneur
activerecord homebrew freetds tiny-tds
I used homebrew (linux port) to install freeTDS and am trying to deploy /bundle install my app with gem tinytds. I get this error output when doing bundle installInstalling tiny_tds (0.5.1) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension./home/deployer/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb /usr/bin/ld: /opt/homebrew/lib/libsybdb.a(dblib.o): relocation R_X86_64_32 against `.rodata’ can not be used when making a shared object; recom
Flackou
ruby-on-rails-3 activerecord mysql2
I’m experiencing trouble upgrading my rails 2.3.14 / ruby 1.8.7 app to 3.1.1/1.9.2 : I have some (ActiveRecord::StatementInvalid) “Mysql2::Error: MySQL server has gone away”errors happening sporadically. It’s important to precise that I never had such issues with the ‘mysql’ gem on 2.3.14 and the exactly same db (so the bug shouldn’t come from mysql (v5.5.10)).Example :$ rails c production Loading production environment (Rails 3.1.1) ruby-1.9.2-p290 :001 > ActiveRecord::Base.connection.active
Orion Edwards
Joel Grannas
ruby-on-rails ruby ruby-on-rails-3 activerecord
I have a model with an has_many association: Charts has_many ChartConditionscharts model has fields for:name (title) table_name (model)The chart_conditions model has fields forassoc_name (to .joins) name (column) value (value) operator (operatorBasically my Chart tells us which model (using the table_name field) I want to run a dynamic query on. Then the chart_conditions for the Chart will tell us which fields in that model to sort on.So In my models that will be queried, i need to dynamically
JavaFan
ruby-on-rails ruby unit-testing activerecord fabrication-gem
I am using Fabrication gem v-2.5.0 on Rails 2.3.16 but get the following errors when I run the unit test cases:Below is the code snippet :First caseFabricate(:some_modal) Fabrication::MisplacedFabricateError: # from /Users/user_xyz/.rvm/gems/ree-1.8.7- 2011.03@project/gems/fabrication-2.5.0/lib/fabrication.rb:51:in `Fabricate’ from (irb):3Second caseFabricate(:some_other_modal) SyntaxError: /Users/user_xyz/.rvm/gems/ree-1.8.7-2011.03@project/gems/fabrication-2.5.0/lib/fabrication/generat
Texas
ruby-on-rails ruby-on-rails-3 activerecord passenger
I previously posted a question (Performing multiple queries on the same model efficiently) which fellow StackExchange users kindly answered and saved me lots of processing time, avoiding lots of queries on my model by storing the results of a SQL query using the .all functionSpecifically they advised @chosenrecords = Everything.where(‘name LIKE ?’, ‘What I want’).order(‘price ASC’).all be usedThis appeared to work fantastically and I used it in a number of places in our code, however, having jus
Victor Bruno
ruby-on-rails ruby-on-rails-3 activerecord
How do I define a model attribute as an expression of another attribute?Example:Class Home < ActiveRecord::Baseattr_accessible :address, :phone_numberNow I want to be able to return an attribute like :area_code, which would be an sql expression like “substr(phone_number, 1,3)”.I also want to be able to use the expression / attribute in a group by query for a report.This seems to perform the query, but does not return an object with named attributes, so how do I use it in a view?Rails Console:
greg
ruby-on-rails ruby-on-rails-3 activerecord
I would like to create complex rest object instances with a single rest call using rails. In the example case below I get an error in the controller when I call new on Person with a parameter hash.I get an error for unexpected type when seeing a ActiveSupport::HashWithIndifferentAccess and not a PhoneNumberThe hash passed from the test contains an array of Hash objects, while the controller action parameters create ActiveSupport::HashWithIndifferentAccess objects. Any suggestions to fix the err
Mario
ruby-on-rails ruby activerecord associations
When working with activerecord I notice that while constructing associations, the reciprocal association is provided automatically only if the reciprocal model has already been saved. If it has not yet been saved, this reciprocal association must be defined manually. I am wondering if this is intentional or a bug, since the only difference in it working or failing is whether the reciprocal model has been saved or not.I hopefully clarified this with the three scenarios described in the followin
JW8
ruby-on-rails ruby-on-rails-3 activerecord
I have a legacy table with (horrible) column names like LYEAR#2, LYEAR#3 … LYEAR#9I setup a model for it named GlamasIf I have: accounts = Glamas.all account_mains = accounts.collect(&:ACCOUNT_MAIN)It breaks with this error:SyntaxError: compile error /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:273: syntax error, unexpected kUNDEF, expecting ‘)’undef :LYEAR#9?^ /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:274: sy
crispy
ruby-on-rails activerecord arel scopes
I have encountered some unexpected behavior in Active Record (3.2.13):There is a simple scope on my model:class User < ActiveRecord::Basescope :verified, lambda { where(‘verified = 1’) } endThis can be used fine on its own:User.verified.to_sql#=> “SELECT \”users\”.* FROM \”users\” WHERE (verified = 1)”When I concatenate where-clauses, they are anded as expected:User.where(company_id: 1).where(company_id: 2).to_sql”SELECT \”users\”.* FROM \”users\” WHERE \”users\”.\”company_id\” = 1 AND \
finpingvin
sql ruby-on-rails ruby ruby-on-rails-3 arel
I have trouble with using Arel to aggregate 2 columns in the same query. When I run this, the whole server freezes for a minute, before the rails dev-server crashes. I suspect an infinite loop :). Maybe I have misunderstood the whole concept of Arel, and I would be grateful if anybody could have a look at it.The expected result of this query is something like this: [{:user_id => 1, :sum_account_charges => 300, :sum_paid_debts => 1000},…]a_account_charges = Table(:account_charges) a_paid_debts
Jack Juiceson
sql ruby-on-rails activerecord arel squeel
tl;drHow to convert below SQL to Arel(or whatever is considered standard in Rails)@toplist = ActiveRecord::Base.connection.execute(‘select ci.crash_info_id,count(distinct(user_guid))[Occurences], c.md5 from crashes ci join crash_infos c on c.id=crash_info_id group by ci.crash_info_idorder by [Occurences] desc’)— end of tl;dr —-I’m working on a small web project, it’s goal is to take our customers crash reports(when our desktop app crashes, we send diagnostics to our servers), analyze them an
stephan.com
sql ruby-on-rails-3 arel
I’m desperately trying to make sense of Arel, mostly because I hate dealing with SQL; I was doing so well, but I’ve hit a wall.I’ve been working in Rails 3.0.0, and I’m trying to make a complex query with some math in it. The real case is rather more complex, but I’ve simplified a bit. In my example, I have a table with a particular string field, and I want a count of all the records, as well as a count for each of two possible values of that field, grouped by a foreign id.Under Rails 3.0.0, I
neezer
sql ruby-on-rails-3 postgresql activerecord arel
UPDATE: So thanks to @Erwin Brandstetter, I now have this:def self.unique_users_by_company(company)users = User.arel_tablecards = Card.arel_tableusers_columns = User.column_names.map { |col| users[col.to_sym] }cards_condition = cards[:company_id].eq(company.id).and(cards[:user_id].eq(users[:id]))User.joins(:cards).where(cards_condition).group(users_columns).order(‘min(cards.created_at)’) end… which seems to do exactly what I want. There are two shortcomings that I would still like to have addr
Adam Lassek
ruby-on-rails ruby-on-rails-3 join multiple-databases arel
I’m trying to move my User account and session data into a separate database so that we can eventually share it across multiple applications.I’ve seen plenty of people online saying to use establish_connection to tell a model to connect to a different db, but I am unable to get this to work.config/database.ymldevelopment:adapter: mysql2encoding: utf8reconnect: truepool: 5host: localhostdatabase: project_name_developmentauthentication:adapter: mysql2encoding: utf8reconnect: truepool: 5host: local
Kevin Sylvestre
ruby-on-rails ruby activerecord arel
I have the following example query:source = “(SELECT DISTINCT source.* FROM (SELECT * FROM items) AS source) AS items” items = Item.select(“items.*”).from(source).includes([:images]) p items # [#<Item id: 1>, #<Item id:2>]However running:p items.count Results in NoMethodError: undefined methodmap’ for Arel::Nodes::SqlLiteral`I appreciate the query is silly, however the non-simplifieid query is a bit too complicated to copy and this was the smallest crashing version I could create. An
David Tuite
ruby-on-rails ruby-on-rails-3 activerecord geocoding arel
I have a bus model and an event model. Each bus is going to an event:class Bus < ActiveRecord::Basebelongs_to :eventbelongs_to :origin endclass Event < ActiveRecord::Basehas_many :buses endAs you can see, each bus also has an origin (the place it leaves from). An origin can have many buses leaving from it. Origins are geocoded (by the [Geocoder gem][1]) on creation so that they have a latitude and longitude associated with them.class Origin < ActiveRecord::Basehas_many :busesgeocoded_by
Dmytrii Nagirniak
sql ruby-on-rails ruby activerecord arel
How can you combine 2 different conditions using logical OR instead of AND?NOTE: 2 conditions are generated as rails scopes and can’t be easily changed into something like where(“x or y”) directly.Simple example:admins = User.where(:kind => :admin) authors = User.where(:kind => :author)It’s easy to apply AND condition (which for this particular case is meaningless):(admins.merge authors).to_sql #=> select … from … where kind = ‘admin’ AND kind = ‘author’But how can you produce the f
Elliot
sql ruby-on-rails subquery arel
I am trying to build this query in ARel:SELECT FLOOR(AVG(num)) FROM ( SELECT COUNT(attendees.id) AS num, meetings.club_id FROM `meetings` INNER JOIN `attendees` ON `attendees`.`meeting_id` = `meetings`.`id` WHERE (`meetings`.club_id = 1) GROUP BY meetings.id) tmp GROUP BY tmp.club_idIt returns the average number of attendees per meeting, per club. (a club has many meetings and a meeting has many attendees)So far I have (declared in class Club < ActiveRecord::Base):num_attendees = meetings.sel
Web site is in building