How would I go about creating a polymorphic has_and_belongs_to_many relationship with Rails/ActiveRecord?
Most of the examples I see involve creating a belongs_to relationship which limits my polymorphic-side to being related to only one parent:
Table: Task
Table: Tasks_Targets
Table: CustomerStore
Table: SoftwareSystem
Both Custom...
I have x,y data coming in from a [coordinates1] database (GIS - but this could be any database). I have my application with it's own coordinate system, referencing THE SAME MAP.
I have established that a linear relationship exists between coordinates1(x,y) and coordinates2(x,y) as I have subtracted two different coordinates1 and coordin...
My question is more of a best practices question on how to implement unowned relationships with Google App Engine. I am using JDO to do my persistence and like recommended in the google docs I'm persisting my list of unowned relationships like so:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements...
Hi,
I'm working on an application developed using Zend Framework. I have defined relationships in models, and can use them happily, e.g:
$rowset = $row->findManyToManyRowset('People', 'Jobs');
However, i've hit a problem where the rowset is returned has column names that are the same in 'People' and 'Jobs', and therefore, merges the...
Hi,
I'm building a social networking website. I have a table of Users. Each user can have a number of other users as friends, so I have a second table Friends:
user_id
friend_id
Based on this answer I'm trying to create the relationships. I have,
class User < ActiveRecord::Base
has_many :friends, :dependent => :destroy
has_many :...
I have a one-to many relationship in Rails:
class User < ActiveRecord::Base
has_many :activities, :order => "added_at DESC"
class Activity < ActiveRecord::Base
belongs_to :user
I have a method in Activity:
def self.test_message(user, message)
user.activities << Activity.create do |activity|
activity.message = message
...
Just as on StackOverflow, in my app a User can write Questions and can also provide Answers:
class User < ActiveRecord::Base
has_many :questions
has_many :answers
end
class Question < ActiveRecord::Base
has_many :answers
belongs_to :user
end
class Answer < ActiveRecord::Base
belongs_to :question
belongs_to :user
end
My ...
Using CakePHP:
I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper.
The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tr...
Say you have departments and employees and each department has several employees, but each employee can also be part of several departments.
So there is a many-to-many relationship between employees and departments. When deleting a department I would like to delete all employees that are only part of that department and nullify the rela...
I'm working on an application which has data imported from a foreign (and wholly unchangeable) source. I'll simplify some of the tables to explain the problem. Below are the tables with their primary keys.
invoices (doc_number, date_printed, batch_number)
headers (doc_number, date_printed, batch_number)
deliveries (doc_number...
My DjangoApp is using categories to generate a navigation and to put stuff in those categories.
There are two types of categories:
ParentCategories (top categories)
ChildCategories (sub categories that have a ParentCategory as a parent)
Because those to categories are so similar I don't want to use two different models.
This is my c...
Assuming you have the following database table:
create table Names (
Id INT IDENTITY NOT NULL,
Name NVARCHAR(100) not null,
ParentNameId INT null,
primary key (Id)
)
create index IX_Name on Names (Name)
alter table Names
add constraint FK_NameNames
foreign key (ParentNameId)
references Names
This allows the ...
Hi, I have the following YAML schema for organising users in Doctrine:
Person:
tableName: people
columns:
id:
type: integer
primary: true
autoincrement: true
firstname:
type: string
notnull: true
lastname:
type: string
notnull: true
User:
inheritance:
extends: Person
t...
I have the following situation in LINQ: I have an object (a blog "Post") that has a "Status" field which can take on different values, and there's a table listing all these values (this table just has Id, Desc).
Now, since the relationship between both tables is created, in the Model, Post.Status is not an int, but an instance of "PostSt...
I'm having some trouble with a recursive relationship in core data. I've got a managed object called a "SearchCategory", and that category can have "Categories" and it can also have a "Category." In the managed object modeler, I've got two relationships set up on the SearchCategory entity, and both point back to the SearchCategory enti...
Hi all,
I've got what is hopefully a simple question - I've got two entities - List and ListItem - and there's a one-to-many relationship set up between them, all good.
My problem comes when I'm trying to perform a fetchrequest which will return the listitems sectioned up by an attribute of the listitem. I can't perform a fetchrequest...
Hello!
Very new to UML and system design.
We're at the stage of doing a class diagram in the design phase and are struggling to figure out how to implement a requirement. Here's the problem:
We have a Person class that is composed of a Name class and a ContactDetails class. Contact details class is composed of a MobileNumber and an E...
i dont get 1-n relationship.
have read some aritcles but still cant figure it out.
i get 1-many, 1:1 and many-to-many.
but what does 1-n mean?
...
In Master-Detail relationships, do Detail-tables contain ID columns?
Or, should it?
In Northwind database, OrderDetail doesn't have an ID column.
...
Hi,
Is it possible to set up a double relationship in a Rails scaffold?
For example, if I had a user model and a private message model, the pm table would need to keep track of both the sender and recipient.
Obviously, for a single relationship I would just do this:
ruby script/generate scaffold pm title:string content:string user:ref...