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
Message from discussion Mongomapper Foreign Key?

Received: by 10.52.67.167 with SMTP id o7mr453282vdt.1.1346254058769;
        Wed, 29 Aug 2012 08:27:38 -0700 (PDT)
X-BeenThere: mongomapper@googlegroups.com
Received: by 10.220.148.143 with SMTP id p15ls1457539vcv.9.gmail; Wed, 29 Aug
 2012 08:27:38 -0700 (PDT)
Received: by 10.66.90.102 with SMTP id bv6mr295570pab.34.1346254057979;
        Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
Received: by 10.66.90.102 with SMTP id bv6mr295569pab.34.1346254057961;
        Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
Return-Path: <pezho...@gmail.com>
Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51])
        by gmr-mx.google.com with ESMTPS id p7si499396pby.0.2012.08.29.08.27.37
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
Received-SPF: pass (google.com: domain of pezho...@gmail.com designates 209.85.160.51 as permitted sender) client-ip=209.85.160.51;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of pezho...@gmail.com designates 209.85.160.51 as permitted sender) smtp.mail=pezho...@gmail.com; dkim=pass header...@gmail.com
Received: by pbbro8 with SMTP id ro8so1525814pbb.24
        for <mongomapper@googlegroups.com>; Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=e2CVCm08Jbl2yIZwO4GuSgtciPziz+weGuO62biBn6w=;
        b=TG5qrEJ9ZD1XaYJQCn0TH6gEiCmVveLHO7Urll4RCqbnbK33z8s6QJCvlSsmPglm9j
         Xqxn1LYZatn7Wgmp+OCWKSvCVOBx+lWE0B7gsQH+u80YWMRq/qgmZQPw/z6Bz+JDNzzo
         Y9NngTY0PIZ2DKiyfEZ4PknaDS3Sr3jd1LCW/eENWC3DWsOpsc1NvecBvxm/JXsr3eWl
         itSZPqLJe2qqUOkTRqVhjJZXdLXfCahe19G/p7rsdead+tDnYqdHm6fTkZAboYgrzqrd
         M0k8ryqXFyZvPyWn3LlboPqQ4y1xRN0ks/bty2NB3z4FSlabVZ8bVgfkmwqMCaDRhgtU
         IZ9g==
MIME-Version: 1.0
Received: by 10.68.224.161 with SMTP id rd1mr5527818pbc.133.1346254057775;
 Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
Received: by 10.66.230.227 with HTTP; Wed, 29 Aug 2012 08:27:37 -0700 (PDT)
In-Reply-To: <503E34CA.9020...@gmail.com>
References: <8d3b94d6-94c4-4aae-9c59-65db0862039a@googlegroups.com>
	<503E33C3.8010...@gmail.com>
	<CAO+Ytt=nUvZT4iUF8MTWsgTVA20ZvMWbyBH48MN3Zh_+-rh...@mail.gmail.com>
	<503E34CA.9020...@gmail.com>
Date: Wed, 29 Aug 2012 16:27:37 +0100
Message-ID: <CAO+YttnOEw+nqM0=40oV+vKQZwOwf_XdcR0XVqSgwx_o88F...@mail.gmail.com>
Subject: Re: [MongoMapper] Mongomapper Foreign Key?
From: Stuart Harrison <pezho...@gmail.com>
To: mongomapper@googlegroups.com
Content-Type: multipart/alternative; boundary=e89a8ff24ff6e421e204c86932c8

--e89a8ff24ff6e421e204c86932c8
Content-Type: text/plain; charset=ISO-8859-1

Brilliant. Thanks.

On Wed, Aug 29, 2012 at 4:27 PM, Jon Kern <jonker...@gmail.com> wrote:

>  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 <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.
>>
>> 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 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
>

--e89a8ff24ff6e421e204c86932c8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Brilliant. Thanks.<br><br><div class=3D"gmail_quote">On Wed, Aug 29, 2012 a=
t 4:27 PM, Jon Kern <span dir=3D"ltr">&lt;<a href=3D"mailto:jonkernpa@gmail=
.com" target=3D"_blank">jonker...@gmail.com</a>&gt;</span> wrote:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex">

 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>Stuart, here are some examples<br>
      <a href=3D"https://github.com/JonKernPA/mongo_examples/tree/master/us=
er_event" target=3D"_blank">https://github.com/JonKernPA/mongo_examples/tre=
e/master/user_event</a><br>
      <br>
      look at the user class<div class=3D"im"><br>
      <pre cols=3D"72">jon

blog: <a href=3D"http://technicaldebt.com" target=3D"_blank">http://technic=
aldebt.com</a>
twitter: <a href=3D"http://twitter.com/JonKernPA" target=3D"_blank">http://=
twitter.com/JonKernPA</a>
</pre></div>
      Stuart Harrison said the following on 8/29/12 11:24 AM:<br>
    </div><div><div class=3D"h5">
    <blockquote type=3D"cite">Cool, thanks for that. Appreciated. I shall c=
ontinue
      to have a play with that in mind :)<br>
      <br>
      <div class=3D"gmail_quote">On Wed, Aug 29, 2012 at 4:22 PM, Jon Kern
        <span dir=3D"ltr">&lt;<a href=3D"mailto:jonker...@gmail.com" target=
=3D"_blank">jonker...@gmail.com</a>&gt;</span>
        wrote:<br>
        <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex">just talking
          out loud without deep thinking or trying anything... or
          looking at your code, so it might be total bunk...<br>
          <br>
          have you noticed that an association has =A0an object_id on the
          single side?<br>
          <br>
          and, on the many side, you could even simply use an array of
          object IDs.<br>
          <br>
          i think if you play around with a simple example classes and
          associations, you will see some opportunity to do whatever you
          need.<br>
          <br>
          if you still need help, ping the list.<br>
          <br>
          sorry for being short, but i wanted to drop this idea your way
          sooner rather than later so that you can act on it.<br>
          <br>
          jon<br>
          <br>
          blog: <a href=3D"http://technicaldebt.com" target=3D"_blank">http=
://technicaldebt.com</a><br>
          twitter: <a href=3D"http://twitter.com/JonKernPA" target=3D"_blan=
k">http://twitter.com/JonKernPA</a><br>
          <br>
          Stuart Harrison said the following on 8/29/12 11:02 AM:
          <div>
            <div><br>
              <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">
                Hi,<br>
                <br>
                I&#39;m currently using Mongomapper within a Padrino projec=
t
                where I&#39;m importing data from an external source. The
                main object (Application) has two associated document
                types, Activity and Notice.<br>
                <br>
                However, I&#39;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.<br>
                <br>
                I&#39;ve tried an EmbeddedDocument, but this causes issues
                as I have to delete all the associated data, rather than
                updating it, which isn&#39;t ideal.<br>
                <br>
                I&#39;ve tried the following, but without any luck:<br>
                <br>
                class Application<br>
                =A0 include MongoMapper::Document<br>
                =A0 ensure_index [[:latlng, &#39;2d&#39;]]<br>
                <br>
                =A0 key :refval, String<br>
                =A0 key :pkeyval, String<br>
                =A0 key :applicantname, String<br>
                =A0 key :latlng, Array<br>
                =A0 key :address, String<br>
                =A0 key :occupier, String<br>
                =A0 key :type, String<br>
                =A0 key :casetype, String<br>
                =A0 key :tradingname, String<br>
                =A0 key :closingdate, Date<br>
                =A0 key :recieveddate, Date<br>
                =A0 key :details, String<br>
                =A0 key :usetype, String<br>
                =A0 key :status, String<br>
                =A0 key :validfrom, Date<br>
                =A0 timestamps!<br>
                <br>
                =A0 many :activities, :foreign_key =3D&gt; :pkeyval<br>
                =A0 many :notices, :foreign_key =3D&gt; :pkeyval<br>
                end<br>
                <br>
                class Activity<br>
                =A0 include MongoMapper::Document<br>
                <br>
                =A0 key :keyval, String<br>
                =A0 key :pkeyval, String<br>
                =A0 key :type, String<br>
                =A0 key :cycle, String<br>
                =A0 key :open, String<br>
                =A0 key :close, String<br>
                <br>
                =A0 belongs_to :application, :foreign_key =3D&gt; :pkeyval<=
br>
                end<br>
                <br>
                class Notice<br>
                =A0 include MongoMapper::Document<br>
                <br>
                =A0 key :keyval, String<br>
                =A0 key :pkeyval, String<br>
                =A0 key :recieveddate, Date<br>
                =A0 key :startdate, Date<br>
                =A0 key :enddate, Date<br>
                =A0 key :days, String<br>
                =A0 key :hours, String<br>
                =A0 key :activities, Array<br>
                <br>
                =A0 belongs_to :application, :foreign_key =3D&gt; :pkeyval<=
br>
                end<br>
                <br>
                Any ideas where I&#39;m going wrong?<br>
                -- <br>
                You received this message because you are subscribed to
                the Google<br>
                Groups &quot;MongoMapper&quot; group.<br>
                For more options, visit this group at<br>
                <a href=3D"http://groups.google.com/group/mongomapper?hl=3D=
en?hl=3Den" target=3D"_blank">http://groups.google.com/group/mongomapper?hl=
=3Den?hl=3Den</a>
                <br>
              </blockquote>
              <br>
              -- <br>
              You received this message because you are subscribed to
              the Google<br>
              Groups &quot;MongoMapper&quot; group.<br>
              For more options, visit this group at<br>
              <a href=3D"http://groups.google.com/group/mongomapper?hl=3Den=
?hl=3Den" target=3D"_blank">http://groups.google.com/group/mongomapper?hl=
=3Den?hl=3Den</a><br>
            </div>
          </div>
        </blockquote>
      </div>
      <br>
      -- <br>
      You received this message because you are subscribed to the Google<br=
>
      Groups &quot;MongoMapper&quot; group.<br>
      For more options, visit this group at<br>
      <a href=3D"http://groups.google.com/group/mongomapper?hl=3Den?hl=3Den=
" target=3D"_blank">http://groups.google.com/group/mongomapper?hl=3Den?hl=
=3Den</a>
    </blockquote>
    <br>
  </div></div></div><div class=3D"HOEnZb"><div class=3D"h5">


<p></p>

-- <br>
You received this message because you are subscribed to the Google<br>
Groups &quot;MongoMapper&quot; group.<br>
For more options, visit this group at<br>
<a href=3D"http://groups.google.com/group/mongomapper?hl=3Den?hl=3Den" targ=
et=3D"_blank">http://groups.google.com/group/mongomapper?hl=3Den?hl=3Den</a=
>
</div></div></blockquote></div><br>

--e89a8ff24ff6e421e204c86932c8--