trouble with nestedBy

0 views
Skip to first unread message

bpope

unread,
Nov 12, 2009, 7:58:06 PM11/12/09
to restfulx-framework
Hi,

RestfulX is fantastic! Thank you for your efforts.

I'm trying to get the hang of it on a project, but I've been having
some trouble understanding how the nestedBy option works - or more
specifically why I don't seem to be able to index a collection of
(only) associated records.

I have models like so:

Project
has_many :images

Image
belongs_to :project

And I modified routes.rb to include:
map.resources :projects, :has_many => :images

Then in flex, I'm trying to show just the associated images based on
the selected project:

private function onProjectSelect():void {
project = RxUtils.clone(projectsList.selectedItem) as Project;
projectImages = Rx.models.index(Image, {nestedBy:[project]});
}

with the dataProvider of a list component bound to {projectImages}.

When I test this, the correct url is being sent to the server (http://
localhost/projects/1/images.fxml) and you can see the server receive
"Parameters: {"project_id"=>"1"}". The response, however, always
includes all of the Image records, rather than just the associated
ones (with the matching project_id). Same thing if I bypass flex and
just request the url above in the browser.

Clearly something's not right on the Rails side. Do I need something
special in the controller for this to work? Or is this some kind of
caching issue?

I'm on Rails 2.3.4, in case that's relevant.

Thanks so much,

- Ben

sahliali

unread,
Nov 13, 2009, 3:38:19 AM11/13/09
to restfulx-framework
first put in your model project.as the relation with images :

[HasMany]
public var images:ModelsCollection;

also your model image.as

[Lazy]
[BelongsTo]
public var project:Project;

then in your controller images_controller do this :


def index
@project = Project.find(params[:project_id])
render :fxml => @project.images.to_fxml()
end

bpope

unread,
Nov 13, 2009, 4:37:39 PM11/13/09
to restfulx-framework
Thank you! It was just that controller bit that I needed. It works
perfectly now.
Reply all
Reply to author
Forward
0 new messages