SerializeJSON() and ORM watch out!

I'm not sure if this is a bug or the way ColdFusion 9.0.1 works, but today I had an issue with the way ColdFusion was serialising an ORM Entity.

I was making a simply AJAX call and in CF using serialiseJSON() method on an ORM object. My issue was that any object that had a property that was an array of other objects was not being returned.

I posted the issue on stackoverflow but then I remembered having the same issue in a Google Group Post on Taffy. I remember resolving this at the time by splitting up the object and basically recreating it again. I was about to do the same thing then on the Adobe livedocs and spotted "remotingFetch"

Quote: "If remotingFetch is false, then the value of that attribute is not sent over flash remoting. The attribute is true by default for all properties. However, for ORM CFCs where persistent = true, the value of the remotingFetch attribute is set to false, by default, for one-to-one, one-to-many, many-to-one, or many-to-many relationships. After enabling this on my relationship it fixed the issue! However as this was referred to under "flash remoting." I missed it the first time around."

After enabling this on my relationship it fixed the issue! As this was referred to under "flash remoting." I missed it the first time around. Just something to watch out for.

Sep27

Mura: New ORM Tag Attribute

I have just been informed on the Google Group for Slatwall Ecommerce that the hardworking Mura team have push out a minor update recently. The change in version 5.4.4456 + allows you better integration for ORM within your Mura plugins. True to the style of BR, it's super easy to configure too.

Within your plugin config XML file just add the following attribute...

view plain print about
1<ormcfclocation>your path here</ormcfclocation>

You can also configure custom tags paths with the new tag attribute, which is cool! Greg and the ten24 team that created the Slatwall Ecommerce Plugin have been making real good use of this new feature. See for yourself by download at GitHub.

Apr20

Head Spin Moment ORM many-to-many Help?

I am trying to understand if this is correct way of looking at ORM and a many-to-many relationship.

Below I have two tables. Users and Monsters. A user can have many monsters, and a monster can have many users. Therefore I have a many-to-many relationship. Now I decide to include a join table called mostercollected to normalise the table somewhat. So below is what I come up with.

view plain print about
1/**
2* user
3*/

4component output="false" persistent="true" {
5
6property name="user_id" column="user_id" type="numeric"
7ormtype="int" fieldtype="id" generator="increment";
8
9property name="user_name" column="user_name"
10type="string" ormtype="string";
11    
12     /* link tables */    
13property name="monsters" fieldtype="many-to-many"
14CFC="monsters" FKColumn="user_id" singularname="monsters"
15inversejoincolumn="monster_id" linktable="monstersCollected";
16
17 users function init() output=false{
18 return this;
19 }
20
21}
22
23
24
25
26/**
27* monsters
28*/

29component output="false" persistent="true" {
30
31property name="monster_id" column="monster_id" type="numeric"
32ormtype="int" fieldtype="id" generator="increment";
33
34property name="monster_name" column="monster_name" type="string"
35ormtype="string" ;
36
37/* link tables */
38property name="users" fieldtype="many-to-many" CFC="users"
39FKColumn="monster_id" singularname="monsters"
40     inversejoincolumn="user_id" linktable="monstersCollected";
41
42 monsters function init() output=false{
43 return this;
44 }
45
46}
47
48
49 /* Join table */    
50
51
52
53component entityname="UserMonster" persistent="true" accessors="true"
54table="monstersCollected"
55{
56 property name="user_id"
57 fieldtype="id,many-to-one"
58 cfc="users"
59 cascade="all"
60 fkcolumn="user_id";
61
62 property name="monster_id"
63 fieldtype="id,many-to-one"
64 cfc="monsters"
65 cascade="all"
66 fkcolumn="monster_id";
67
68}

Now if I dump a user to screen, yes I can see all the monsters that each user has (cool), but the array continues down more, showing all monsters and all users that belong to that monster, effectively repeating data (bad, right?).

  • User1
    • Monster2
      • User1
      • User2
    • Monster1
      • User1
      • User2
  • User2
    • Monster2
      • User1
      • User2
    • Monster1
      • User1
      • User2

My concern is that of performance. If every time I want to get a user and I then get monsters + monster again and users that belong to that monster (head spin, moment), this seems like a lot of overhead when all I want is a list of the following...

  • User1
    • Monster2
    • Monster1
  • User2
    • Monster2
    • Monster1

Is this the issue I am making it out to be? Or have fundamentally missed the boat on this one and misunderstood completely?

Sep20