I am building a Rails application accessing a legacy system. The data model contains Customers which can have one or more Subscriptions. A Subscription always belong to one and only one Customer. Though not needed, this association is represented through a join table "subscribes", which do not have an id column:
Column | Type...
I'm saving whole HTML documents in the database with ActiveRecord. I can see in the logs that correct INSERT statements are being generated and sent to MySQL but when I actually look in the database after the save has completed, the content is truncated.
It appears that entities in the document are causing this truncation. I can ...
I have a model Painting which has a Paintingtitle in each language and a Paintingdescription in each language:
class Painting < ActiveRecord::Base
has_many :paintingtitles, :dependent => :destroy
has_many :paintingdescriptions, :dependent => :destroy
end
class Paintingtitle < ActiveRecord::Base
belongs_to :painting
belongs_to...
I've got a tiny model (let's call it "Node") that represents a tree-like structure. Each node contains only a name and a reference to its father:
class Node < ActiveRecord::Base
validates_presence_of :name, :parent_id
end
The table isn't very big - less than 100 elements. It's updated rarely - in the last 4 months 20 new elements we...
Is there a way to turn OFF autosave in Rails? I don't want modifications to an association to automatically save to the database UNTIL I call save on the parent object.
some_parent.some_children << child #should not save, just adds to the association!
some_parent.save #now parent and children are saved!
It this possible or am I ba...
My application accepts file uploads, with some metadata being stored in the DB, and the file itself on the file system. I am trying to make the metadata visible in the application before the file upload and post-processing are finished, but because saves are transactional, I have had no success. I have tried the callbacks and calling c...
I have a many-to-many association between a User class and a Table class. Additionally, i have a one-to-many association between the User and the Table (one User ultimately owns the table). I am trying to access all of the tables which the user may access (essentially joining both associations).
Additionally, it would be nice to do this...
Hi Everyone,
Are there any ways to retrieve the database connection string where my ruby is connected? what i would like to get is the:
1) Database name where the ruby is connected
2) The username of the SQL Server
3) Password of the SQL Server
4) Server name
I want to store it in session variables.
(I'am using MS SQL Server.)
Pleas...
Is is possible in rails to setup on model which is dependant on a join from two tables? This would mean that for the the model record to be found/updated/destroyed there would need to be both records in both database tables linked together in a join. The model would just be all the columns of both tables wrapped together which may then b...
Rails newbie here.
I have a list of items which can have a status represented by an integer (right now its just 1=active 0=inactive).
What I want is next to each item a link to change the status of that item. So it might look like this:
A nice item - Enable
Another pretty item - Disable
I can't think of how to make the link...
Hi,
I am trying to populate a ruby on rails select box from a database query, the data comes from 3 tables.
My query
@data = Session.all :include => { :term => :courses }
Object
!ruby/object:Session
attributes:
created_at: 2010-06-17 22:12:05
term_id: "15"
updated_at: 2010-06-17 22:12:05
id: "3"
course_id: "1"
attributes_cache: ...
UPDATE
Got it to work by using has_and_belongs_to_many
Anyone know why this works ?
Hi,
I get the following error when saving with active record
undefined method `reflect_on_association' for Class:Class
my relationships look like this :
class Contact < ActiveRecord::Base
has_many :classes
has_many :sessions, :through => :cl...
ActiveRecord gives you an interesting error when you try to eager-load a non-existent association. It looks something like this:
ActiveRecord::ConfigurationError: Association named 'secondary_complaint' was not found; perhaps you misspelled it?
Now why the hell would anybody want to preload a non-existent association? Check this out.
...
I am implementing a Rails application that needs to aggregate search results from N independent heterogeneous databases. An example use case would be:
User queries "xpto"
The query is submitted to all the databases registered on the system
The results are transformed and combined in a predefined format
User gets the results
The appli...
All that I will do is insert records into the database.
However, I would definitly like the database-independence that Ruby/ActiveRecord can offer me.
What would be the reccommended choice?
Using simple insert queries, and rewriting them, and also maintaining my own database class for things as batch insertions;
Using the power of Act...
Hi,
I am trying to find all terms and courses that apply to a contact.
Here are my models
class Register < ActiveRecord::Base
belongs_to :session
belongs_to :contact
end
class Session < ActiveRecord::Base
belongs_to :term
belongs_to :course
has_many :registers
has_many :contacts, :through => :registers
end
Here is the find...
This is probably very simple, but I'm quite new to ruby and active record.
I've got a CSV dump of a database which I'm trying to import to a database using DataMapper. I'm having trouble understanding which type of relationships I should define in the models so that it matches what is defined CSV.
Here's what data I've got from the CS...
I know it's possible to create Any relationships where the related record could be of any type.
Is there a way to tell the ActiveRecord the records in a table belong to many different types even when there is no relationships? For example I have a table in which there is a string field that stores the type of each record in table. I'd l...
In my application I have 2 classes like this:
class City < ActiveRecord::Base
has_many :events
end
class Event < ActiveRecord::Base
belongs_to :city
attr_accessible :title, :city_id
end
If I create city object:
city = City.create!(:name => 'My city')
and then pass parameters to create event like this:
event = Event.create!...
I want to create a model 'Relation' which extends ActiveRecord::Base, set it's table name as 'questions_tags', and without primary key. What should I do?
class Relation < ActiveRecord::Base
set_table_name 'questions_tags' # set table name, right?
# how to define 'no-pk'?
end
UPDATE
Hi, guys. I know use 'create_table' can solv...