activerecord

activerecord and mongo / mongo-mapper bridge

感情迁移 提交于 2019-12-24 06:19:20
问题 I have a project which I have used Active Record and which I'd like to add some new features using MongoDB. Rather than re-invent the wheel and re-write my entire site, how can I integrate 2 models together, one which use MongoMapper and the other ActiveRecord (postgres). I've found that others have done it successfully, but no examples: http://groups.google.com/group/mongomapper/browse_thread/thread/ec5ad00e18e7dd2c/887b8b0b904a8f73?lnk=gst&q=activerecord#887b8b0b904a8f73 For example, I have

activerecord and mongo / mongo-mapper bridge

房东的猫 提交于 2019-12-24 06:19:02
问题 I have a project which I have used Active Record and which I'd like to add some new features using MongoDB. Rather than re-invent the wheel and re-write my entire site, how can I integrate 2 models together, one which use MongoMapper and the other ActiveRecord (postgres). I've found that others have done it successfully, but no examples: http://groups.google.com/group/mongomapper/browse_thread/thread/ec5ad00e18e7dd2c/887b8b0b904a8f73?lnk=gst&q=activerecord#887b8b0b904a8f73 For example, I have

XML Serialization is not including milliseconds in datetime field from Rails model

妖精的绣舞 提交于 2019-12-24 05:58:47
问题 By default, the datetime field from the database is being converted and stripping off the milliseconds: some_datetime => "2009-11-11T02:19:36Z" attribute_before_type_cast('some_datetime') => "2009-11-11 02:19:36.145" If I try to overrride the accessor for this attribute like; def some_datetime attribute_before_type_cast('some_datetime') end when I try "to_xml" for that model, I get the following error: NoMethodError (undefined method `xmlschema' for "2009-11-11 02:19:36.145":String): I have

A situation where ActiveRecord and SQL do not return the same results due to unknown OID being treated as String

…衆ロ難τιáo~ 提交于 2019-12-24 05:55:22
问题 I have a problem. Earlier I posted a similar question to the one I am about to ask which was answered and can be found here for context ActiveRecord Count and SQL count do not match That question had to do with counting a query result. In this question, instead of not getting the same count result, I am getting different object results. Here is the ActiveRecord code: scope :unverified_with_no_associations, -> { find_by_sql("SELECT DISTINCT(accounts.id, accounts.email) FROM accounts WHERE

NoMethodError: undefined method `created_at' for in Rails

佐手、 提交于 2019-12-24 05:54:23
问题 So here is a object I retrieved from the ActiveRecord other = [#<Referrer id: 16, name: "Other", published: true, created_at: "2011-07-11 16:22:00", updated_at: "2011-07-11 16:22:00">] Why can't I do other.created_at while I can do other.name ? Here is the model: class Referrer < ActiveRecord::Base end The error I'm getting: NoMethodError: undefined method `created_at' for #<ActiveRecord::Relation:0x1035763c8> What have I missed? 回答1: If you'll notice, other is actually an ActiveRecord:

Postgres / Rails Active Record — query for rounded float value

坚强是说给别人听的谎言 提交于 2019-12-24 04:49:06
问题 I'm using Postgres in a Rails app. Storing Lat/Lon in the database as float values. I want to be able to compare locations' lat/lons, but I only know how to do exact equality: Location.where(lat: @lat, lon: @lon) My issue is, I want Postgres to read, say 71.233434 as equal to 71.233545, or something. In other words, can I query for rounded equality, or equality within a range? I've Googled around for this pretty extensively (maybe using the wrong terms? I can't think of it. "Active Record

Accessing a join-model attribute stored in a join table created with #create_join_table

≯℡__Kan透↙ 提交于 2019-12-24 04:47:09
问题 In a Rails ( 4.1.5 / ruby 2.0.0p481 / win64 ) application I have a many-to-many relationship between Student and Course and a join model StudentCourse which represents the association, which has an additional attribute called "started", which is set by default on "false". I also have added an index in the join table made of the student_id and the course_id, and set a unique check on that, like this t.index [:student_id, :course_id], :unique => true, :name => 'by_student_and_course' Now I see

Validates_Overlap Gem Multiple Scopes Overwriting Eachother

*爱你&永不变心* 提交于 2019-12-24 04:38:04
问题 I'm using Validates_Overlap Gem which can be found here: https://github.com/robinbortlik/validates_overlap The essence is I have two rooms that can be booked. I want the validation to step in when the same room already has a CONFIRMED booking in the SAME room. It shouldn't throw me an error when the other room is booked, or if the same room is booked but hasn't been confirmed. My code so far is as follows validates :start_time, :end_time, :overlap => { :exclude_edges => ["starts_at", "ends_at

How to import a BIG SQL file into a rails database? [duplicate]

谁说我不能喝 提交于 2019-12-24 04:37:19
问题 This question already has answers here : MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes (14 answers) Closed 6 years ago . I've got a quite huge (> 8mo) sql file that basically creates 2 tables and populate them with data. It's a dump generated from Sequel Pro. My first idea was to read the file line by line and run an "execute" command, but I've got an error that my string was too big. Mysql2::Error: Got a packet bigger than 'max_allowed_packet' bytes Is there any way

Overwriting/Adding an ActiveRecord association dynamically using a singleton class

时光怂恿深爱的人放手 提交于 2019-12-24 04:13:25
问题 The business logic is this: Users are in a Boat through a join table, I guess let's call that model a Ticket. But when a User instance wants to check who else is on the boat, there's a condition that asks if that user has permission see everyone on the Boat, or just certain people on the Boat. If a User can see everyone, the normal deal is fine: some_user.boats.first.users returns all users with a ticket for that boat. But for some users, the only people that are on the boat (as far as they