I'd inherit from ARFetchAttribute overriding Bind().
ARFetchAttribute delegates to ARFetcher so you'd have to replace that
with your own fetcher.

http://svn.castleproject.org:8080/svn/castle/trunk/MonoRail/Castle.MonoRail.ActiveRecordSupport/ARFetchAttribute.cs
http://svn.castleproject.org:8080/svn/castle/trunk/MonoRail/Castle.MonoRail.ActiveRecordSupport/ARFetcher.cs


On May 21, 7:40 pm, jsmorris <[email protected]> wrote:
> In your action, you can use ARFetch to fetch your objects from the
> database as long as you have that object's id in your params.  What if
> you wanted to fetch your objects using a different property of the
> object, say a name.  Is that possible?
>
> Below is part of an action I have on a controller that is creating a
> new Technology object and saving it to the database.  As you can see,
> I use ARFetch to fetch all these objects and then associate them to my
> Technology instance.  I just look at this code and think there must be
> a better way.
>
> Also, my String q is from a text box that the user types in that I
> then need to go look up in my database to get a User object, hence my
> question about using ARFetch to look up an object by Name instead of
> Id.  Is this the place to create my own custom DataBind object based
> on ARFetch?
>
> Just looking for pointers from others as to if there is anything I can
> do to improve this code.
>
> Thanks,
>
> Jason
>
> ====================================
>
>         [AccessibleThrough(Verb.Post)]
>         public void Create([ARDataBind("technology", Validate = true)]
> Technology technology, String q,
>             [ARFetch("technology.project.id")] Project project,
>             [ARFetch("technology.technologynode.id")] TechnologyNode techNode,
>             [ARFetch("technology.organization.id")] Organization org,
>             [ARFetch("technology.orgunit.id")] OrgUnit orgunit,
>             [ARFetch("technology.status.id")] Status status)
>         {
>             technology.Project = project;
>             technology.TechnologyNode = techNode;
>             technology.Owner = _userService.Find(q);
>             technology.Organization = org;
>             technology.OrgUnit = orgunit;
>             technology.Status = status;
>             technology.EstimatedApprovalDate =
> (Params["estimatedapprovaldate"].IsNullOrEmpty()) ? new DateTime?() :
> _timeService.Parse(Params["estimatedapprovaldate"]);
>
>             ....
>
>             technology.Create();
>
>             RedirectToAction("show", String.Format("id={0}", technology.Id));
>         }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to