Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Mongomapper Foreign Key?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Stuart Harrison  
View profile  
 More options Aug 29 2012, 11:02 am
From: Stuart Harrison <pezho...@gmail.com>
Date: Wed, 29 Aug 2012 08:02:13 -0700 (PDT)
Local: Wed, Aug 29 2012 11:02 am
Subject: Mongomapper Foreign Key?

Hi,

I'm currently using Mongomapper within a Padrino project where I'm
importing data from an external source. The main object (Application) has
two associated document types, Activity and Notice.

However, I'd like to specify the foreign key myself, rather than use the
internal Mongo ID, as the foreign key is in the data export, which I import
via a rake task.

I've tried an EmbeddedDocument, but this causes issues as I have to delete
all the associated data, rather than updating it, which isn't ideal.

I've tried the following, but without any luck:

class Application
  include MongoMapper::Document
  ensure_index [[:latlng, '2d']]

  key :refval, String
  key :pkeyval, String
  key :applicantname, String
  key :latlng, Array
  key :address, String
  key :occupier, String
  key :type, String
  key :casetype, String
  key :tradingname, String
  key :closingdate, Date
  key :recieveddate, Date
  key :details, String
  key :usetype, String
  key :status, String
  key :validfrom, Date
  timestamps!

  many :activities, :foreign_key => :pkeyval
  many :notices, :foreign_key => :pkeyval
end

class Activity
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :type, String  
  key :cycle, String
  key :open, String
  key :close, String

  belongs_to :application, :foreign_key => :pkeyval
end

class Notice
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :recieveddate, Date
  key :startdate, Date
  key :enddate, Date
  key :days, String  
  key :hours, String
  key :activities, Array

  belongs_to :application, :foreign_key => :pkeyval
end

Any ideas where I'm going wrong?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Kern  
View profile  
 More options Aug 29 2012, 11:22 am
From: Jon Kern <jonker...@gmail.com>
Date: Wed, 29 Aug 2012 11:22:43 -0400
Local: Wed, Aug 29 2012 11:22 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?
just talking out loud without deep thinking or trying anything... or
looking at your code, so it might be total bunk...

have you noticed that an association has  an object_id on the single side?

and, on the many side, you could even simply use an array of object IDs.

i think if you play around with a simple example classes and
associations, you will see some opportunity to do whatever you need.

if you still need help, ping the list.

sorry for being short, but i wanted to drop this idea your way sooner
rather than later so that you can act on it.

jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA

Stuart Harrison said the following on 8/29/12 11:02 AM:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart Harrison  
View profile  
 More options Aug 29 2012, 11:24 am
From: Stuart Harrison <pezho...@gmail.com>
Date: Wed, 29 Aug 2012 16:24:49 +0100
Local: Wed, Aug 29 2012 11:24 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?

Cool, thanks for that. Appreciated. I shall continue to have a play with
that in mind :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Kern  
View profile  
 More options Aug 29 2012, 11:27 am
From: Jon Kern <jonker...@gmail.com>
Date: Wed, 29 Aug 2012 11:27:06 -0400
Local: Wed, Aug 29 2012 11:27 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?
Stuart, here are some examples
https://github.com/JonKernPA/mongo_examples/tree/master/user_event

look at the user class
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Stuart Harrison said the following on 8/29/12 11:24 AM:
Cool, thanks for that. Appreciated. I shall continue to have a play with that in mind :)

On Wed, Aug 29, 2012 at 4:22 PM, Jon Kern <jonkernpa@gmail.com> wrote:
just talking out loud without deep thinking or trying anything... or looking at your code, so it might be total bunk...

have you noticed that an association has  an object_id on the single side?

and, on the many side, you could even simply use an array of object IDs.

i think if you play around with a simple example classes and associations, you will see some opportunity to do whatever you need.

if you still need help, ping the list.

sorry for being short, but i wanted to drop this idea your way sooner rather than later so that you can act on it.

jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA

Stuart Harrison said the following on 8/29/12 11:02 AM:

Hi,

I'm currently using Mongomapper within a Padrino project where I'm importing data from an external source. The main object (Application) has two associated document types, Activity and Notice.

However, I'd like to specify the foreign key myself, rather than use the internal Mongo ID, as the foreign key is in the data export, which I import via a rake task.

I've tried an EmbeddedDocument, but this causes issues as I have to delete all the associated data, rather than updating it, which isn't ideal.

I've tried the following, but without any luck:

class Application
  include MongoMapper::Document
  ensure_index [[:latlng, '2d']]

  key :refval, String
  key :pkeyval, String
  key :applicantname, String
  key :latlng, Array
  key :address, String
  key :occupier, String
  key :type, String
  key :casetype, String
  key :tradingname, String
  key :closingdate, Date
  key :recieveddate, Date
  key :details, String
  key :usetype, String
  key :status, String
  key :validfrom, Date
  timestamps!

  many :activities, :foreign_key => :pkeyval
  many :notices, :foreign_key => :pkeyval
end

class Activity
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :type, String
  key :cycle, String
  key :open, String
  key :close, String

  belongs_to :application, :foreign_key => :pkeyval
end

class Notice
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :recieveddate, Date
  key :startdate, Date
  key :enddate, Date
  key :days, String
  key :hours, String
  key :activities, Array

  belongs_to :application, :foreign_key => :pkeyval
end

Any ideas where I'm going wrong?
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Kern  
View profile  
 More options Aug 29 2012, 11:27 am
From: Jon Kern <jonker...@gmail.com>
Date: Wed, 29 Aug 2012 11:27:25 -0400
Local: Wed, Aug 29 2012 11:27 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?
i mean, look at the event class
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Jon Kern said the following on 8/29/12 11:27 AM:
Stuart, here are some examples
https://github.com/JonKernPA/mongo_examples/tree/master/user_event

look at the user class
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Stuart Harrison said the following on 8/29/12 11:24 AM:
Cool, thanks for that. Appreciated. I shall continue to have a play with that in mind :)

On Wed, Aug 29, 2012 at 4:22 PM, Jon Kern <jonkernpa@gmail.com> wrote:
just talking out loud without deep thinking or trying anything... or looking at your code, so it might be total bunk...

have you noticed that an association has  an object_id on the single side?

and, on the many side, you could even simply use an array of object IDs.

i think if you play around with a simple example classes and associations, you will see some opportunity to do whatever you need.

if you still need help, ping the list.

sorry for being short, but i wanted to drop this idea your way sooner rather than later so that you can act on it.

jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA

Stuart Harrison said the following on 8/29/12 11:02 AM:

Hi,

I'm currently using Mongomapper within a Padrino project where I'm importing data from an external source. The main object (Application) has two associated document types, Activity and Notice.

However, I'd like to specify the foreign key myself, rather than use the internal Mongo ID, as the foreign key is in the data export, which I import via a rake task.

I've tried an EmbeddedDocument, but this causes issues as I have to delete all the associated data, rather than updating it, which isn't ideal.

I've tried the following, but without any luck:

class Application
  include MongoMapper::Document
  ensure_index [[:latlng, '2d']]

  key :refval, String
  key :pkeyval, String
  key :applicantname, String
  key :latlng, Array
  key :address, String
  key :occupier, String
  key :type, String
  key :casetype, String
  key :tradingname, String
  key :closingdate, Date
  key :recieveddate, Date
  key :details, String
  key :usetype, String
  key :status, String
  key :validfrom, Date
  timestamps!

  many :activities, :foreign_key => :pkeyval
  many :notices, :foreign_key => :pkeyval
end

class Activity
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :type, String
  key :cycle, String
  key :open, String
  key :close, String

  belongs_to :application, :foreign_key => :pkeyval
end

class Notice
  include MongoMapper::Document

  key :keyval, String
  key :pkeyval, String
  key :recieveddate, Date
  key :startdate, Date
  key :enddate, Date
  key :days, String
  key :hours, String
  key :activities, Array

  belongs_to :application, :foreign_key => :pkeyval
end

Any ideas where I'm going wrong?
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en



 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart Harrison  
View profile  
 More options Aug 29 2012, 11:27 am
From: Stuart Harrison <pezho...@gmail.com>
Date: Wed, 29 Aug 2012 16:27:37 +0100
Local: Wed, Aug 29 2012 11:27 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?

Brilliant. Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stuart Harrison  
View profile  
 More options Aug 30 2012, 5:00 am
From: Stuart Harrison <pezho...@gmail.com>
Date: Thu, 30 Aug 2012 02:00:18 -0700 (PDT)
Local: Thurs, Aug 30 2012 5:00 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?

Just to pick up on this again, I think I've got this nailed now. I didn't
need to specify the foreign key in the many part, and also had to override
the primary key in my Activities object with the following:

key :_id, String

Cheers

Stuart


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Kern  
View profile  
 More options Aug 31 2012, 9:02 am
From: Jon Kern <jonker...@gmail.com>
Date: Fri, 31 Aug 2012 09:01:57 -0400
Local: Fri, Aug 31 2012 9:01 am
Subject: Re: [MongoMapper] Mongomapper Foreign Key?
glad you worked it out!
jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Stuart Harrison said the following on 8/30/12 5:00 AM:
Just to pick up on this again, I think I've got this nailed now. I didn't need to specify the foreign key in the many part, and also had to override the primary key in my Activities object with the following:

key :_id, String

Cheers

Stuart
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »