After severe headaches, I set up a new, clean site using the post
example from earlier. (no comments or multiple manytomany this time,
the problem runs deeper, it appears)

Here is the Transfer config:

<package name="users">
        <object name="user" table="users"
decorator="components.decorators.users">
                <id name="userID" type="numeric" />
                <property name="email" type="string" column="email"
nullable="false" />

                <onetomany name="posts" lazy="true" proxied="true">
                        <link to="posts.post" column="userID"/>
                        <collection type="array">
                        </collection>
                </onetomany>
    </object>
</package>

<package name="posts">
        <object name="post" table="posts">
                <id name="postID" type="numeric" />
                <property name="postTitle" type="string"
column="postTitle" nullable="false" />
                <manytomany name="tags" table="posttags"
proxied="true" lazy="true">
                        <link to="posts.post" column="postID"/>
                        <link to="tags.tag" column="tagID"/>
                        <collection type="array">
                        </collection>
                </manytomany>
        </object>
</package>

<package name="tags">
        <object name="tag" table="tags"
decorator="components.decorators.tags">
                <id name="tagID" type="numeric" />
                <property name="tagTitle" type="string"
column="tagTitle" nullable="false" />
        </object>
</package>

I have one handler with one method:

<!--- // default method --->
        <cffunction name="default" access="public" returntype="void"
output="false" cache="true">
                <cfargument name="Event" 
type="coldbox.system.beans.requestContext">
        <cfset var rc = event.getCollection()>

        <cfscript>
                //get user
                user = instance.Transfer.get("users.user", 1);
                rc.user = user;

                //get posts array from user
                rc.myPosts = user.getPostsArray();

                //get post
                post = instance.Transfer.get("posts.post", 1);

                //get tag
                tag = instance.Transfer.get("tags.tag", 1);

                //add tag to post
                post.addTags(tag);

                //add post to request collection
                rc.post = post;

                //save post
                instance.Transfer.save(post);

                </cfscript>

                <cfset Event.setLayout(rc.viewPrefix & "Layout.Default")>

        </cffunction>

My database is:

[posts]
postID
userID
postTitle

[users]
userID
email

[tags]
tagID
tagTitle

[posttags]
postTagID
postID
tagID

Using the exact code above, my tags are not added to the database, and
the dump below shows no tags in the array:

<cfdump var="#rc.post.getTagsArray()#">

However, if I comment out this line to be:

//              instance.Transfer.save(post);

The dump of <cfdump var="#rc.post.getTagsArray()#"> shows the new tag
added to the array.

As soon as I try to save the object, though, the tags are gone and not
saved to the database.

Now, if I comment out this line to be:

//              rc.myPosts = user.getPostsArray();

And then uncomment the save line again to be:

                instance.Transfer.save(post);

Then the save works and the tags are added to the database and still
in the rc.post object after save. So, just calling getPostsArray()
causes any subsequent tags added to post not to save. They are added
to the object correctly, but as soon as save() is called they are
dropped from the array and not saved.

Alternatively, if I create the post object before I call getPostsArray
():

//get post
                post = instance.Transfer.get("posts.post", 1);

//get posts array from user
                rc.myPosts = user.getPostsArray();

Then the save works and the tags show up.

So, the behavior is:

Tags will not save or stay added to the post object after a
Transfer.save(post) if user.getPostsArray() has ever been called
before the post object has been created.

These are the only files in my clean site.

The problem here is that I want to get a list of posts, so I need to
call getPostsArray(), then I want to click to go to a form to edit the
post and add tags. The problem comes when I submit the form. The tags
are not saved since I had called getPostsArray() first to get the list
of posts on the page before. It doesn't matter if I call getPostsArray
() in the same handler, as in my example above, or on a completely
different handler. Once this method has been called at all, my tags
will not stay added to the object after a save().

Perhaps I'm again missing something glaring or a ColdBox / Transfer
setting, but as of right now, this is odd behavior to me.
--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to