Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage examples #1

Open
tauren opened this issue Jan 12, 2011 · 3 comments
Open

Usage examples #1

tauren opened this issue Jan 12, 2011 · 3 comments

Comments

@tauren
Copy link

tauren commented Jan 12, 2011

It would be really great if you could provide some examples of how this library is used. I'm not asking for full documentation or anything (although that would be sweet!). But some sample code that illustrates the basic features and could help get developers up to speed quickly would help.

Thanks!

@juggy
Copy link
Owner

juggy commented Jan 12, 2011

This project is far from complete, but it was an idea of parsing a single json tree and building complete relations from it.

So if you use rails you would load for exemple in your html output:
Projects = new ProjectCollection(<%=Projects.all(:include=>[:committers, :note]).to_json%>);
And you define your relation like this in your Project model initializer:
//args are the base model, the type of related model, the name of the local attribute and finally the name of the foreign attribute (if you need it)
_.extend(this, new Porkepic.EmbeddedInMany(this, Commiter, "committers", "project"))
// args: base model, related model type, local attribute
_.extend this, new Porkepic.HasOne(this, Note, "note"))

Your can "have" models (so the json looks like {model1_att1: "tata", model1_att2 : {model2_att1: ""}} ) or you can be embedded in another model (meaning you have only a referring id to that model)

I do not have more time right now to move this project forward, but if there is some need it could be done.

I felt it was too heavy for light applications. On big application with heavy data it could be interesting to use this type of api, but it would have to load lazily to avoid long page load.

@elcuervo
Copy link

And how do you access the relation? with the get method from Backbone?

@juggy
Copy link
Owner

juggy commented Feb 23, 2011

Yes you do. Names are based on the relation names you give. In the above example: committers on the project model and project on the committer model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants