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']]
> 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']]
> 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
On Wed, Aug 29, 2012 at 4:22 PM, Jon Kern <jonker...@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.
> 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']]
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']]
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
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']]
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
>> 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']]
>>> 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
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:
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: