Is there a better way of writing this code? It just doesn't sit right with me, I feel like there is something really 'rails like' that I should already know:
belongs_to :parent_in_use
belongs_to :parent_template
def after_create
new_parent_in_use = ParentInUse.create!(self.parent_template.attributes)
self.update_attribute(:parent_i...
I have a project that necessarily spans several databases.
One database has tables:
CREATE TABLE device {
device_uid integer unsigned not null primary key auto_increment,
os varchar(50),
name varchar(50)
}
CREATE TABLE platform {
platform_id integer unsigned not null primary key auto_increment,
name varchar(50)
}
The oth...
I am fairly new to Ruby on Rails, and I clearly have an active record association problem, but I can't solve it on my own.
Given the three model classes with their associations:
# application_form.rb
class ApplicationForm < ActiveRecord::Base
has_many :questions, :through => :form_questions
end
# question.rb
class Question < ActiveR...
I have a many to many relationship between A and B. (I know I can consider refactoring etc, but that's another matter).
my Code does something like this:
// given aId is the Id of an instance of A, and A has a many to many set of B's
A a = myActiveSession.Get<A>(aId);
a.Bs.Add(new B() {Name="dave"});
and I get an exception bec...
Hello,
By any chance is it possible to create a conditional association with DataMapper?
For example:
I want the User have n Apps just if that user have the attribute :developer => true
something like this:
class User
include DataMapper::Resource
property :id, Serial
property :name, String, :nullable => false
property :scre...
I'm currently mucking about with CakePHP, deciding if I'll use it in an upcoming web application.
The problem is, I've got several tables which at some point share relevant data with each other. If I were to write all the code myself I would use an SQL query using rather a lot of different joins and subqueries. But from what I understan...
I want to implement a messaging system for my app.
I have users.
What exactly should I do?
create a messages model with foreign two user foreign keys??.. what would be the most approproate way of getting this done?
My worry is that if I query "message.user" I wont know if Id be getting the sender of the receiver of the message
...
This is probably quite simple but I haven't yet been able to wrap my head around the problem.
I have 3 tables... (well more than that) but in this scenario 3 that matter.
Places
Bookings and
Ratings
Places has_many bookings
Each booking has_one rating (because the user only rates once) and belongs_to (a) Place
Ratings belong_to (a) ...
In Rails, to automatically count associations, you do:
class Script
has_many: chapters
end
class Chapter
belongs_to :script
end
and you add a Chapters_count column into the Script model.
Now, what if you want to count the number of paragraphs in a Script *without having a script_id key in the paragraph model ?*
class Script
ha...
Hello,
I have set up Auth and ACL successfully on my cakePHP app.
How, now i want to build an interface for managing the ACL's, ARO's and ACO's
ARO's and ACO's where pretty easy to build using the tree behavior.
ACL how ever got me a little messed up... especially when it came to defining the model relations.
I've named my aco and ar...
I run the risk of palm-to-forehead here, but I can't quite figure out how to do this with Rails' ActiveRecord sugar.
I have a tickets table that has two columns (submitter_id and assignee_id) that should each reference a different user from the users table (specifically the id column in the users table). I'd like to be able to do things...
I am new to RoR and still playing with associations. I need to have two references to a particular model in another model. The scaffolded code doesn't work and I get a "uninitialized constant" error.
Generation commands:
script/generate scaffold BaseModel name:string
script/generate scaffold NewModel name:string base1:references base2:...
Suppose we have the standard Post & Comment models, with Post having accepts_nested_attributes_for :commments and :autosave => true set.
We can create a new post together with some new comments, e.g.:
@post = Post.new :subject => 'foo'
@post.comments.build :text => 'bar'
@post.comments.first # returns the new comment 'bar'
@post.commen...
I have a couple models (Site and Server) that are related to eachother via has_many :through. they also both belong_to :user. in my sites/new view, I create a new site, and I create a new server using a nested form.fields_for :servers. Everything works as expected, except for that the server that ends up getting created doesn't have a ...
I am using .NET's RIA services/LinqToSql to expose my data to a Silverlight 3 client. In the database, an Item table has more than one association to another table, User. As an example, the Item table has both CreatedByUser and ModifiedByUser fields. When I use the RIA services wizard to create my DomainService (and metadata), I find ...
Hi,
I've got a problem with a has_many :through association, i cant call the u1.UsersProfileAttributes.find_by_ProfileAttribute_name("icq") method, rails means that this method doesn't exist. The method u1.UsersProfileAttributes.find_by_ProfileAttribute_id(3) works correctly. u1 is a user object. I don't know whats the problem, because ...
I have been trying to create an association relation between two tables, intake and module . Each intake has a one-to-many relationship with the modules.
However there is a coursework assigned to each module, and each coursework has a duedate which is unique to each intake.
I tried this but it didnt work:
intake_modules_table = Tabl...
I'm rendering display objects to the stage depending on the given XML elements, as you can see here:
PageRenderer.as
private static var curElements:Dictionary = new Dictionary();
//renders the current page
private static function renderCode(pageCode:XML):void
{
if (pageCode)
{
/...
OK, I am little bit lost...
I am pretty new to PHP, and i am trying to use CakePHP for my web-site.
my DB is composed of two tables:
users with user_id, name columns
copies with copy_id, copy_name, user_id (as foreign key to users) columns.
and I have the matching CakePHP elements:
User and Copy as a model
UserController as con...
Hi there, this is my first time posting here, looks like a great site! I'm struggling with a has_many association. I have a diary application. The Model players are as follows:
User
UserFriend
UserFoodProfile
I want to be able to get at all the foods that a user's friends have eaten. So, I want to be able to get: current_user.fri...